File: policies_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (70 lines) | stat: -rw-r--r-- 1,839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//go:build acceptance || clustering || policies
// +build acceptance clustering policies

package v1

import (
	"testing"

	"github.com/gophercloud/gophercloud/acceptance/clients"
	"github.com/gophercloud/gophercloud/acceptance/tools"
	"github.com/gophercloud/gophercloud/openstack/clustering/v1/policies"
	th "github.com/gophercloud/gophercloud/testhelper"
)

func TestPoliciesCRUD(t *testing.T) {
	client, err := clients.NewClusteringV1Client()
	th.AssertNoErr(t, err)
	client.Microversion = "1.5"

	policy, err := CreatePolicy(t, client)
	th.AssertNoErr(t, err)
	defer DeletePolicy(t, client, policy.ID)

	// Test listing policies
	allPages, err := policies.List(client, nil).AllPages()
	th.AssertNoErr(t, err)

	allPolicies, err := policies.ExtractPolicies(allPages)
	th.AssertNoErr(t, err)

	var found bool
	for _, v := range allPolicies {
		if v.ID == policy.ID {
			found = true
		}
	}

	th.AssertEquals(t, found, true)

	// Test Get policy
	getPolicy, err := policies.Get(client, policy.ID).Extract()
	th.AssertNoErr(t, err)
	tools.PrintResource(t, getPolicy)

	// Test updating policy
	updateOpts := policies.UpdateOpts{
		Name: policy.Name + "-UPDATE",
	}

	t.Logf("Attempting to update policy: %s", policy.ID)
	updatePolicy, err := policies.Update(client, policy.ID, updateOpts).Extract()
	th.AssertNoErr(t, err)

	tools.PrintResource(t, updatePolicy)
	tools.PrintResource(t, updatePolicy.UpdatedAt)

	// Test validating policy
	t.Logf("Attempting to validate policy: %s", policy.ID)
	validateOpts := policies.ValidateOpts{
		Spec: TestPolicySpec,
	}

	validatePolicy, err := policies.Validate(client, validateOpts).Extract()
	th.AssertNoErr(t, err)

	tools.PrintResource(t, validatePolicy)

	th.AssertEquals(t, validatePolicy.Name, "validated_policy")
	th.AssertEquals(t, validatePolicy.Spec.Version, TestPolicySpec.Version)
}