github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/clustering/v1/profiles_test.go (about) 1 //go:build acceptance || clustering || policies 2 // +build acceptance clustering policies 3 4 package v1 5 6 import ( 7 "testing" 8 9 "github.com/gophercloud/gophercloud/internal/acceptance/clients" 10 "github.com/gophercloud/gophercloud/internal/acceptance/tools" 11 "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" 12 th "github.com/gophercloud/gophercloud/testhelper" 13 ) 14 15 func TestProfilesCRUD(t *testing.T) { 16 client, err := clients.NewClusteringV1Client() 17 th.AssertNoErr(t, err) 18 19 profile, err := CreateProfile(t, client) 20 th.AssertNoErr(t, err) 21 defer DeleteProfile(t, client, profile.ID) 22 23 // Test listing profiles 24 allPages, err := profiles.List(client, nil).AllPages() 25 th.AssertNoErr(t, err) 26 27 allProfiles, err := profiles.ExtractProfiles(allPages) 28 th.AssertNoErr(t, err) 29 30 var found bool 31 for _, v := range allProfiles { 32 if v.ID == profile.ID { 33 found = true 34 } 35 } 36 37 th.AssertEquals(t, found, true) 38 39 // Test updating profile 40 updateOpts := profiles.UpdateOpts{ 41 Name: profile.Name + "-UPDATED", 42 } 43 44 newProfile, err := profiles.Update(client, profile.ID, updateOpts).Extract() 45 th.AssertNoErr(t, err) 46 th.AssertEquals(t, newProfile.Name, profile.Name+"-UPDATED") 47 48 tools.PrintResource(t, newProfile) 49 tools.PrintResource(t, newProfile.UpdatedAt) 50 } 51 52 func TestProfileValidate(t *testing.T) { 53 client, err := clients.NewClusteringV1Client() 54 th.AssertNoErr(t, err) 55 client.Microversion = "1.2" 56 57 profile, err := CreateProfile(t, client) 58 th.AssertNoErr(t, err) 59 defer DeleteProfile(t, client, profile.ID) 60 61 opts := profiles.ValidateOpts{ 62 Spec: profile.Spec, 63 } 64 validatedProfile, err := profiles.Validate(client, opts).Extract() 65 th.AssertNoErr(t, err) 66 67 // Do not validate the following fields for AssertDeepEquals() because the actual fields are either missing or hardcoded. 68 profile.CreatedAt = validatedProfile.CreatedAt 69 profile.Domain = validatedProfile.Domain 70 profile.ID = validatedProfile.ID 71 profile.Metadata = validatedProfile.Metadata 72 profile.Name = "validated_profile" 73 profile.UpdatedAt = validatedProfile.UpdatedAt 74 75 th.AssertDeepEquals(t, validatedProfile, profile) 76 tools.PrintResource(t, validatedProfile) 77 }