File: profiles_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 (77 lines) | stat: -rw-r--r-- 2,132 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
71
72
73
74
75
76
77
//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/profiles"
	th "github.com/gophercloud/gophercloud/testhelper"
)

func TestProfilesCRUD(t *testing.T) {
	client, err := clients.NewClusteringV1Client()
	th.AssertNoErr(t, err)

	profile, err := CreateProfile(t, client)
	th.AssertNoErr(t, err)
	defer DeleteProfile(t, client, profile.ID)

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

	allProfiles, err := profiles.ExtractProfiles(allPages)
	th.AssertNoErr(t, err)

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

	th.AssertEquals(t, found, true)

	// Test updating profile
	updateOpts := profiles.UpdateOpts{
		Name: profile.Name + "-UPDATED",
	}

	newProfile, err := profiles.Update(client, profile.ID, updateOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, newProfile.Name, profile.Name+"-UPDATED")

	tools.PrintResource(t, newProfile)
	tools.PrintResource(t, newProfile.UpdatedAt)
}

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

	profile, err := CreateProfile(t, client)
	th.AssertNoErr(t, err)
	defer DeleteProfile(t, client, profile.ID)

	opts := profiles.ValidateOpts{
		Spec: profile.Spec,
	}
	validatedProfile, err := profiles.Validate(client, opts).Extract()
	th.AssertNoErr(t, err)

	// Do not validate the following fields for AssertDeepEquals() because the actual fields are either missing or hardcoded.
	profile.CreatedAt = validatedProfile.CreatedAt
	profile.Domain = validatedProfile.Domain
	profile.ID = validatedProfile.ID
	profile.Metadata = validatedProfile.Metadata
	profile.Name = "validated_profile"
	profile.UpdatedAt = validatedProfile.UpdatedAt

	th.AssertDeepEquals(t, validatedProfile, profile)
	tools.PrintResource(t, validatedProfile)
}