|
8 | 8 | "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" |
9 | 9 | "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" |
10 | 10 | "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" |
| 11 | + "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf-premium/v1/cloud" |
11 | 12 | "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf-premium/v1/instances" |
12 | 13 | th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" |
13 | 14 | ) |
@@ -79,3 +80,80 @@ func TestWafPremiumInstanceWorkflow(t *testing.T) { |
79 | 80 | th.AssertNoErr(t, err) |
80 | 81 | th.AssertEquals(t, instanceUpdated.Name, updatedName) |
81 | 82 | } |
| 83 | + |
| 84 | +func TestWafPremiumCloudInstance(t *testing.T) { |
| 85 | + client, err := clients.NewWafdV1Client() |
| 86 | + th.AssertNoErr(t, err) |
| 87 | + |
| 88 | + queryOpts := cloud.DeleteOpts{ |
| 89 | + EnterpriseProjectID: os.Getenv("OS_ENTERPRISE_PROJECT_ID"), |
| 90 | + } |
| 91 | + if queryOpts.EnterpriseProjectID == "" { |
| 92 | + queryOpts.EnterpriseProjectID = "0" |
| 93 | + } |
| 94 | + |
| 95 | + currentSubscription, err := cloud.Get(client) |
| 96 | + th.AssertNoErr(t, err) |
| 97 | + if currentSubscription.Type != -1 && currentSubscription.Type != 22 { |
| 98 | + t.Skipf("skipping pay-per-use switch test for existing cloud WAF subscription type %d", currentSubscription.Type) |
| 99 | + } |
| 100 | + |
| 101 | + enableOpts := cloud.EnableOpts{ |
| 102 | + ConsoleArea: "dt", |
| 103 | + EnterpriseProjectID: queryOpts.EnterpriseProjectID, |
| 104 | + } |
| 105 | + initialType := currentSubscription.Type |
| 106 | + |
| 107 | + t.Cleanup(func() { |
| 108 | + latestSubscription, queryErr := cloud.Get(client) |
| 109 | + if queryErr != nil { |
| 110 | + t.Logf("failed to query WAF subscription during cleanup: %v", queryErr) |
| 111 | + return |
| 112 | + } |
| 113 | + |
| 114 | + if initialType == 22 && latestSubscription.Type != 22 { |
| 115 | + if _, restoreErr := cloud.Enable(client, enableOpts); restoreErr != nil { |
| 116 | + t.Logf("failed to restore pay-per-use subscription during cleanup: %v", restoreErr) |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + if initialType == -1 && latestSubscription.Type != -1 { |
| 121 | + if restoreErr := cloud.Disable(client, queryOpts); restoreErr != nil { |
| 122 | + t.Logf("failed to restore unsubscribed state during cleanup: %v", restoreErr) |
| 123 | + } |
| 124 | + } |
| 125 | + }) |
| 126 | + |
| 127 | + if initialType == -1 { |
| 128 | + enableResponse, err := cloud.Enable(client, enableOpts) |
| 129 | + th.AssertNoErr(t, err) |
| 130 | + th.AssertEquals(t, enableResponse.Type, 22) |
| 131 | + |
| 132 | + enabledSubscription, err := cloud.Get(client) |
| 133 | + th.AssertNoErr(t, err) |
| 134 | + th.AssertEquals(t, enabledSubscription.Type, 22) |
| 135 | + |
| 136 | + err = cloud.Disable(client, queryOpts) |
| 137 | + th.AssertNoErr(t, err) |
| 138 | + |
| 139 | + disabledSubscription, err := cloud.Get(client) |
| 140 | + th.AssertNoErr(t, err) |
| 141 | + th.AssertEquals(t, disabledSubscription.Type, -1) |
| 142 | + return |
| 143 | + } |
| 144 | + |
| 145 | + err = cloud.Disable(client, queryOpts) |
| 146 | + th.AssertNoErr(t, err) |
| 147 | + |
| 148 | + disabledSubscription, err := cloud.Get(client) |
| 149 | + th.AssertNoErr(t, err) |
| 150 | + th.AssertEquals(t, disabledSubscription.Type, -1) |
| 151 | + |
| 152 | + enableResponse, err := cloud.Enable(client, enableOpts) |
| 153 | + th.AssertNoErr(t, err) |
| 154 | + th.AssertEquals(t, enableResponse.Type, 22) |
| 155 | + |
| 156 | + enabledSubscription, err := cloud.Get(client) |
| 157 | + th.AssertNoErr(t, err) |
| 158 | + th.AssertEquals(t, enabledSubscription.Type, 22) |
| 159 | +} |
0 commit comments