| 1 |
// test |
| 2 |
package azure |
| 3 |
|
| 4 |
// Copyright 2017 Microsoft Corporation |
| 5 |
// |
| 6 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
// you may not use this file except in compliance with the License. |
| 8 |
// You may obtain a copy of the License at |
| 9 |
// |
| 10 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
// |
| 12 |
// Unless required by applicable law or agreed to in writing, software |
| 13 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
// See the License for the specific language governing permissions and |
| 16 |
// limitations under the License. |
| 17 |
|
| 18 |
import ( |
| 19 |
"encoding/json" |
| 20 |
"io/ioutil" |
| 21 |
"net/http" |
| 22 |
"net/http/httptest" |
| 23 |
"os" |
| 24 |
"path" |
| 25 |
"path/filepath" |
| 26 |
"runtime" |
| 27 |
"testing" |
| 28 |
) |
| 29 |
|
| 30 |
const ( |
| 31 |
batchResourceID = "--batch-resource-id--" |
| 32 |
datalakeResourceID = "--datalake-resource-id--" |
| 33 |
graphResourceID = "--graph-resource-id--" |
| 34 |
keyvaultResourceID = "--keyvault-resource-id--" |
| 35 |
opInsightsResourceID = "--operational-insights-resource-id--" |
| 36 |
ossRDBMSResourceID = "--oss-rdbms-resource-id--" |
| 37 |
cosmosDBResourceID = "--cosmosdb-resource-id--" |
| 38 |
managedHSMResourceID = "--managed-hsm-resource-id--" |
| 39 |
) |
| 40 |
|
| 41 |
// This correlates to the expected contents of ./testdata/test_environment_1.json |
| 42 |
var testEnvironment1 = Environment{ |
| 43 |
Name: "--unit-test--", |
| 44 |
ManagementPortalURL: "--management-portal-url", |
| 45 |
PublishSettingsURL: "--publish-settings-url--", |
| 46 |
ServiceManagementEndpoint: "--service-management-endpoint--", |
| 47 |
ResourceManagerEndpoint: "--resource-management-endpoint--", |
| 48 |
ActiveDirectoryEndpoint: "--active-directory-endpoint--", |
| 49 |
GalleryEndpoint: "--gallery-endpoint--", |
| 50 |
KeyVaultEndpoint: "--key-vault--endpoint--", |
| 51 |
ManagedHSMEndpoint: "--managed-hsm-endpoint--", |
| 52 |
GraphEndpoint: "--graph-endpoint--", |
| 53 |
StorageEndpointSuffix: "--storage-endpoint-suffix--", |
| 54 |
CosmosDBDNSSuffix: "--cosmos-db-dns-suffix--", |
| 55 |
MariaDBDNSSuffix: "--maria-db-dns-suffix--", |
| 56 |
MySQLDatabaseDNSSuffix: "--mysql-database-dns-suffix--", |
| 57 |
PostgresqlDatabaseDNSSuffix: "--postgresql-database-dns-suffix--", |
| 58 |
SQLDatabaseDNSSuffix: "--sql-database-dns-suffix--", |
| 59 |
TrafficManagerDNSSuffix: "--traffic-manager-dns-suffix--", |
| 60 |
KeyVaultDNSSuffix: "--key-vault-dns-suffix--", |
| 61 |
ManagedHSMDNSSuffix: "--managed-hsm-dns-suffix--", |
| 62 |
ServiceBusEndpointSuffix: "--service-bus-endpoint-suffix--", |
| 63 |
ServiceManagementVMDNSSuffix: "--asm-vm-dns-suffix--", |
| 64 |
ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--", |
| 65 |
ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--", |
| 66 |
TokenAudience: "--token-audience", |
| 67 |
ResourceIdentifiers: ResourceIdentifier{ |
| 68 |
Batch: batchResourceID, |
| 69 |
Datalake: datalakeResourceID, |
| 70 |
Graph: graphResourceID, |
| 71 |
KeyVault: keyvaultResourceID, |
| 72 |
OperationalInsights: opInsightsResourceID, |
| 73 |
OSSRDBMS: ossRDBMSResourceID, |
| 74 |
CosmosDB: cosmosDBResourceID, |
| 75 |
ManagedHSM: managedHSMResourceID, |
| 76 |
}, |
| 77 |
} |
| 78 |
|
| 79 |
func TestEnvironment_EnvironmentFromURL_NoOverride_Success(t *testing.T) { |
| 80 |
fileContents, _ := ioutil.ReadFile(filepath.Join("testdata", "test_metadata_environment_1.json")) |
| 81 |
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 82 |
w.WriteHeader(http.StatusOK) |
| 83 |
w.Write([]byte(fileContents)) |
| 84 |
})) |
| 85 |
defer ts.Close() |
| 86 |
|
| 87 |
got, err := EnvironmentFromURL(ts.URL) |
| 88 |
if err != nil { |
| 89 |
t.Error(err) |
| 90 |
} |
| 91 |
if got.Name != "HybridEnvironment" { |
| 92 |
t.Logf("got: %v want: HybridEnvironment", got.Name) |
| 93 |
t.Fail() |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
func TestEnvironment_EnvironmentFromURL_OverrideStorageSuffix_Success(t *testing.T) { |
| 98 |
fileContents, _ := ioutil.ReadFile(filepath.Join("testdata", "test_metadata_environment_1.json")) |
| 99 |
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 100 |
w.WriteHeader(http.StatusOK) |
| 101 |
w.Write([]byte(fileContents)) |
| 102 |
})) |
| 103 |
defer ts.Close() |
| 104 |
overrideProperty := OverrideProperty{ |
| 105 |
Key: EnvironmentStorageEndpointSuffix, |
| 106 |
Value: "fakeStorageSuffix", |
| 107 |
} |
| 108 |
got, err := EnvironmentFromURL(ts.URL, overrideProperty) |
| 109 |
if err != nil { |
| 110 |
t.Error(err) |
| 111 |
} |
| 112 |
if got.StorageEndpointSuffix != "fakeStorageSuffix" { |
| 113 |
t.Logf("got: %v want: fakeStorageSuffix", got.StorageEndpointSuffix) |
| 114 |
t.Fail() |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
func TestEnvironment_EnvironmentFromURL_EmptyEndpoint_Failure(t *testing.T) { |
| 119 |
_, err := EnvironmentFromURL("") |
| 120 |
|
| 121 |
if err == nil { |
| 122 |
t.Fail() |
| 123 |
} |
| 124 |
if err.Error() != "Metadata resource manager endpoint is empty" { |
| 125 |
t.Fail() |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
func TestEnvironment_EnvironmentFromFile(t *testing.T) { |
| 130 |
got, err := EnvironmentFromFile(filepath.Join("testdata", "test_environment_1.json")) |
| 131 |
if err != nil { |
| 132 |
t.Error(err) |
| 133 |
} |
| 134 |
|
| 135 |
if got != testEnvironment1 { |
| 136 |
t.Logf("got: %v want: %v", got, testEnvironment1) |
| 137 |
t.Fail() |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
func TestEnvironment_EnvironmentFromName_Stack(t *testing.T) { |
| 142 |
_, currentFile, _, _ := runtime.Caller(0) |
| 143 |
prevEnvFilepathValue := os.Getenv(EnvironmentFilepathName) |
| 144 |
os.Setenv(EnvironmentFilepathName, filepath.Join(path.Dir(currentFile), "testdata", "test_environment_1.json")) |
| 145 |
defer os.Setenv(EnvironmentFilepathName, prevEnvFilepathValue) |
| 146 |
|
| 147 |
got, err := EnvironmentFromName("AZURESTACKCLOUD") |
| 148 |
if err != nil { |
| 149 |
t.Error(err) |
| 150 |
} |
| 151 |
|
| 152 |
if got != testEnvironment1 { |
| 153 |
t.Logf("got: %v want: %v", got, testEnvironment1) |
| 154 |
t.Fail() |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
func TestEnvironmentFromName(t *testing.T) { |
| 159 |
name := "azurechinacloud" |
| 160 |
if env, _ := EnvironmentFromName(name); env != ChinaCloud { |
| 161 |
t.Errorf("Expected to get ChinaCloud for %q", name) |
| 162 |
} |
| 163 |
|
| 164 |
name = "AzureChinaCloud" |
| 165 |
if env, _ := EnvironmentFromName(name); env != ChinaCloud { |
| 166 |
t.Errorf("Expected to get ChinaCloud for %q", name) |
| 167 |
} |
| 168 |
|
| 169 |
name = "azuregermancloud" |
| 170 |
if env, _ := EnvironmentFromName(name); env != GermanCloud { |
| 171 |
t.Errorf("Expected to get GermanCloud for %q", name) |
| 172 |
} |
| 173 |
|
| 174 |
name = "AzureGermanCloud" |
| 175 |
if env, _ := EnvironmentFromName(name); env != GermanCloud { |
| 176 |
t.Errorf("Expected to get GermanCloud for %q", name) |
| 177 |
} |
| 178 |
|
| 179 |
name = "AzureCloud" |
| 180 |
if env, _ := EnvironmentFromName(name); env != PublicCloud { |
| 181 |
t.Errorf("Expected to get PublicCloud for %q", name) |
| 182 |
} |
| 183 |
|
| 184 |
name = "azurepubliccloud" |
| 185 |
if env, _ := EnvironmentFromName(name); env != PublicCloud { |
| 186 |
t.Errorf("Expected to get PublicCloud for %q", name) |
| 187 |
} |
| 188 |
|
| 189 |
name = "AzurePublicCloud" |
| 190 |
if env, _ := EnvironmentFromName(name); env != PublicCloud { |
| 191 |
t.Errorf("Expected to get PublicCloud for %q", name) |
| 192 |
} |
| 193 |
|
| 194 |
name = "azureusgovernmentcloud" |
| 195 |
if env, _ := EnvironmentFromName(name); env != USGovernmentCloud { |
| 196 |
t.Errorf("Expected to get USGovernmentCloud for %q", name) |
| 197 |
} |
| 198 |
|
| 199 |
name = "AzureUSGovernmentCloud" |
| 200 |
if env, _ := EnvironmentFromName(name); env != USGovernmentCloud { |
| 201 |
t.Errorf("Expected to get USGovernmentCloud for %q", name) |
| 202 |
} |
| 203 |
|
| 204 |
name = "azureusgovernment" |
| 205 |
if env, _ := EnvironmentFromName(name); env != USGovernmentCloud { |
| 206 |
t.Errorf("Expected to get USGovernmentCloud for %q", name) |
| 207 |
} |
| 208 |
|
| 209 |
name = "AzureUSGovernment" |
| 210 |
if env, _ := EnvironmentFromName(name); env != USGovernmentCloud { |
| 211 |
t.Errorf("Expected to get USGovernmentCloud for %q", name) |
| 212 |
} |
| 213 |
|
| 214 |
name = "thisisnotarealcloudenv" |
| 215 |
if _, err := EnvironmentFromName(name); err == nil { |
| 216 |
t.Errorf("Expected to get an error for %q", name) |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
func TestDeserializeEnvironment(t *testing.T) { |
| 221 |
env := `{ |
| 222 |
"name": "--name--", |
| 223 |
"ActiveDirectoryEndpoint": "--active-directory-endpoint--", |
| 224 |
"galleryEndpoint": "--gallery-endpoint--", |
| 225 |
"graphEndpoint": "--graph-endpoint--", |
| 226 |
"serviceBusEndpoint": "--service-bus-endpoint--", |
| 227 |
"keyVaultDNSSuffix": "--key-vault-dns-suffix--", |
| 228 |
"keyVaultEndpoint": "--key-vault-endpoint--", |
| 229 |
"managedHSMDNSSuffix": "--managed-hsm-dns-suffix--", |
| 230 |
"managedHSMEndpoint": "--managed-hsm-endpoint--", |
| 231 |
"managementPortalURL": "--management-portal-url--", |
| 232 |
"publishSettingsURL": "--publish-settings-url--", |
| 233 |
"resourceManagerEndpoint": "--resource-manager-endpoint--", |
| 234 |
"serviceBusEndpointSuffix": "--service-bus-endpoint-suffix--", |
| 235 |
"serviceManagementEndpoint": "--service-management-endpoint--", |
| 236 |
"cosmosDBDNSSuffix": "--cosmos-db-dns-suffix--", |
| 237 |
"mariaDBDNSSuffix": "--maria-db-dns-suffix--", |
| 238 |
"mySqlDatabaseDNSSuffix": "--mysql-database-dns-suffix--", |
| 239 |
"postgresqlDatabaseDNSSuffix": "--postgresql-database-dns-suffix--", |
| 240 |
"sqlDatabaseDNSSuffix": "--sql-database-dns-suffix--", |
| 241 |
"storageEndpointSuffix": "--storage-endpoint-suffix--", |
| 242 |
"trafficManagerDNSSuffix": "--traffic-manager-dns-suffix--", |
| 243 |
"serviceManagementVMDNSSuffix": "--asm-vm-dns-suffix--", |
| 244 |
"resourceManagerVMDNSSuffix": "--arm-vm-dns-suffix--", |
| 245 |
"containerRegistryDNSSuffix": "--container-registry-dns-suffix--", |
| 246 |
"resourceIdentifiers": { |
| 247 |
"batch": "` + batchResourceID + `", |
| 248 |
"datalake": "` + datalakeResourceID + `", |
| 249 |
"graph": "` + graphResourceID + `", |
| 250 |
"keyVault": "` + keyvaultResourceID + `", |
| 251 |
"operationalInsights": "` + opInsightsResourceID + `", |
| 252 |
"ossRDBMS": "` + ossRDBMSResourceID + `", |
| 253 |
"cosmosDB": "` + cosmosDBResourceID + `", |
| 254 |
"managedHSM": "` + managedHSMResourceID + `" |
| 255 |
} |
| 256 |
}` |
| 257 |
|
| 258 |
testSubject := Environment{} |
| 259 |
err := json.Unmarshal([]byte(env), &testSubject) |
| 260 |
if err != nil { |
| 261 |
t.Fatalf("failed to unmarshal: %s", err) |
| 262 |
} |
| 263 |
|
| 264 |
if "--name--" != testSubject.Name { |
| 265 |
t.Errorf("Expected Name to be \"--name--\", but got %q", testSubject.Name) |
| 266 |
} |
| 267 |
if "--management-portal-url--" != testSubject.ManagementPortalURL { |
| 268 |
t.Errorf("Expected ManagementPortalURL to be \"--management-portal-url--\", but got %q", testSubject.ManagementPortalURL) |
| 269 |
} |
| 270 |
if "--publish-settings-url--" != testSubject.PublishSettingsURL { |
| 271 |
t.Errorf("Expected PublishSettingsURL to be \"--publish-settings-url--\", but got %q", testSubject.PublishSettingsURL) |
| 272 |
} |
| 273 |
if "--service-management-endpoint--" != testSubject.ServiceManagementEndpoint { |
| 274 |
t.Errorf("Expected ServiceManagementEndpoint to be \"--service-management-endpoint--\", but got %q", testSubject.ServiceManagementEndpoint) |
| 275 |
} |
| 276 |
if "--resource-manager-endpoint--" != testSubject.ResourceManagerEndpoint { |
| 277 |
t.Errorf("Expected ResourceManagerEndpoint to be \"--resource-manager-endpoint--\", but got %q", testSubject.ResourceManagerEndpoint) |
| 278 |
} |
| 279 |
if "--active-directory-endpoint--" != testSubject.ActiveDirectoryEndpoint { |
| 280 |
t.Errorf("Expected ActiveDirectoryEndpoint to be \"--active-directory-endpoint--\", but got %q", testSubject.ActiveDirectoryEndpoint) |
| 281 |
} |
| 282 |
if "--gallery-endpoint--" != testSubject.GalleryEndpoint { |
| 283 |
t.Errorf("Expected GalleryEndpoint to be \"--gallery-endpoint--\", but got %q", testSubject.GalleryEndpoint) |
| 284 |
} |
| 285 |
if "--key-vault-endpoint--" != testSubject.KeyVaultEndpoint { |
| 286 |
t.Errorf("Expected KeyVaultEndpoint to be \"--key-vault-endpoint--\", but got %q", testSubject.KeyVaultEndpoint) |
| 287 |
} |
| 288 |
if "--managed-hsm-endpoint--" != testSubject.ManagedHSMEndpoint { |
| 289 |
t.Errorf("Expected ManagedHSMEndpoint to be \"--managed-hsm-endpoint--\", but got %q", testSubject.ManagedHSMEndpoint) |
| 290 |
} |
| 291 |
if "--service-bus-endpoint--" != testSubject.ServiceBusEndpoint { |
| 292 |
t.Errorf("Expected ServiceBusEndpoint to be \"--service-bus-endpoint--\", but goet %q", testSubject.ServiceBusEndpoint) |
| 293 |
} |
| 294 |
if "--graph-endpoint--" != testSubject.GraphEndpoint { |
| 295 |
t.Errorf("Expected GraphEndpoint to be \"--graph-endpoint--\", but got %q", testSubject.GraphEndpoint) |
| 296 |
} |
| 297 |
if "--storage-endpoint-suffix--" != testSubject.StorageEndpointSuffix { |
| 298 |
t.Errorf("Expected StorageEndpointSuffix to be \"--storage-endpoint-suffix--\", but got %q", testSubject.StorageEndpointSuffix) |
| 299 |
} |
| 300 |
if "--cosmos-db-dns-suffix--" != testSubject.CosmosDBDNSSuffix { |
| 301 |
t.Errorf("Expected cosmos-db-dns-suffix to be \"--cosmos-db-dns-suffix--\", but got %q", testSubject.CosmosDBDNSSuffix) |
| 302 |
} |
| 303 |
if "--maria-db-dns-suffix--" != testSubject.MariaDBDNSSuffix { |
| 304 |
t.Errorf("Expected maria-db-dns-suffix to be \"--maria-db-dns-suffix--\", but got %q", testSubject.MariaDBDNSSuffix) |
| 305 |
} |
| 306 |
if "--mysql-database-dns-suffix--" != testSubject.MySQLDatabaseDNSSuffix { |
| 307 |
t.Errorf("Expected mysql-database-dns-suffix to be \"--mysql-database-dns-suffix--\", but got %q", testSubject.MySQLDatabaseDNSSuffix) |
| 308 |
} |
| 309 |
if "--postgresql-database-dns-suffix--" != testSubject.PostgresqlDatabaseDNSSuffix { |
| 310 |
t.Errorf("Expected postgresql-database-dns-suffix to be \"--postgresql-database-dns-suffix--\", but got %q", testSubject.PostgresqlDatabaseDNSSuffix) |
| 311 |
} |
| 312 |
if "--sql-database-dns-suffix--" != testSubject.SQLDatabaseDNSSuffix { |
| 313 |
t.Errorf("Expected sql-database-dns-suffix to be \"--sql-database-dns-suffix--\", but got %q", testSubject.SQLDatabaseDNSSuffix) |
| 314 |
} |
| 315 |
if "--key-vault-dns-suffix--" != testSubject.KeyVaultDNSSuffix { |
| 316 |
t.Errorf("Expected StorageEndpointSuffix to be \"--key-vault-dns-suffix--\", but got %q", testSubject.KeyVaultDNSSuffix) |
| 317 |
} |
| 318 |
if "--managed-hsm-dns-suffix--" != testSubject.ManagedHSMDNSSuffix { |
| 319 |
t.Errorf("Expected StorageEndpointSuffix to be \"--managed-hsm-dns-suffix--\", but got %q", testSubject.ManagedHSMDNSSuffix) |
| 320 |
} |
| 321 |
if "--service-bus-endpoint-suffix--" != testSubject.ServiceBusEndpointSuffix { |
| 322 |
t.Errorf("Expected StorageEndpointSuffix to be \"--service-bus-endpoint-suffix--\", but got %q", testSubject.ServiceBusEndpointSuffix) |
| 323 |
} |
| 324 |
if "--asm-vm-dns-suffix--" != testSubject.ServiceManagementVMDNSSuffix { |
| 325 |
t.Errorf("Expected ServiceManagementVMDNSSuffix to be \"--asm-vm-dns-suffix--\", but got %q", testSubject.ServiceManagementVMDNSSuffix) |
| 326 |
} |
| 327 |
if "--arm-vm-dns-suffix--" != testSubject.ResourceManagerVMDNSSuffix { |
| 328 |
t.Errorf("Expected ResourceManagerVMDNSSuffix to be \"--arm-vm-dns-suffix--\", but got %q", testSubject.ResourceManagerVMDNSSuffix) |
| 329 |
} |
| 330 |
if "--container-registry-dns-suffix--" != testSubject.ContainerRegistryDNSSuffix { |
| 331 |
t.Errorf("Expected ContainerRegistryDNSSuffix to be \"--container-registry-dns-suffix--\", but got %q", testSubject.ContainerRegistryDNSSuffix) |
| 332 |
} |
| 333 |
if batchResourceID != testSubject.ResourceIdentifiers.Batch { |
| 334 |
t.Errorf("Expected ResourceIdentifiers.Batch to be "+batchResourceID+", but got %q", testSubject.ResourceIdentifiers.Batch) |
| 335 |
} |
| 336 |
if datalakeResourceID != testSubject.ResourceIdentifiers.Datalake { |
| 337 |
t.Errorf("Expected ResourceIdentifiers.Datalake to be "+datalakeResourceID+", but got %q", testSubject.ResourceIdentifiers.Datalake) |
| 338 |
} |
| 339 |
if graphResourceID != testSubject.ResourceIdentifiers.Graph { |
| 340 |
t.Errorf("Expected ResourceIdentifiers.Graph to be "+graphResourceID+", but got %q", testSubject.ResourceIdentifiers.Graph) |
| 341 |
} |
| 342 |
if keyvaultResourceID != testSubject.ResourceIdentifiers.KeyVault { |
| 343 |
t.Errorf("Expected ResourceIdentifiers.KeyVault to be "+keyvaultResourceID+", but got %q", testSubject.ResourceIdentifiers.KeyVault) |
| 344 |
} |
| 345 |
if opInsightsResourceID != testSubject.ResourceIdentifiers.OperationalInsights { |
| 346 |
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be "+opInsightsResourceID+", but got %q", testSubject.ResourceIdentifiers.OperationalInsights) |
| 347 |
} |
| 348 |
if ossRDBMSResourceID != testSubject.ResourceIdentifiers.OSSRDBMS { |
| 349 |
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be "+ossRDBMSResourceID+", but got %q", testSubject.ResourceIdentifiers.OSSRDBMS) |
| 350 |
} |
| 351 |
if cosmosDBResourceID != testSubject.ResourceIdentifiers.CosmosDB { |
| 352 |
t.Errorf("Expected ResourceIdentifiers.CosmosDB to be "+cosmosDBResourceID+", but got %q", testSubject.ResourceIdentifiers.CosmosDB) |
| 353 |
} |
| 354 |
if managedHSMResourceID != testSubject.ResourceIdentifiers.ManagedHSM { |
| 355 |
t.Errorf("Expected ResourceIdentifiers.ManagedHSM to be "+managedHSMResourceID+", but got %q", testSubject.ResourceIdentifiers.ManagedHSM) |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
func TestRoundTripSerialization(t *testing.T) { |
| 360 |
env := Environment{ |
| 361 |
Name: "--unit-test--", |
| 362 |
ManagementPortalURL: "--management-portal-url", |
| 363 |
PublishSettingsURL: "--publish-settings-url--", |
| 364 |
ServiceManagementEndpoint: "--service-management-endpoint--", |
| 365 |
ResourceManagerEndpoint: "--resource-management-endpoint--", |
| 366 |
ActiveDirectoryEndpoint: "--active-directory-endpoint--", |
| 367 |
GalleryEndpoint: "--gallery-endpoint--", |
| 368 |
KeyVaultEndpoint: "--key-vault--endpoint--", |
| 369 |
GraphEndpoint: "--graph-endpoint--", |
| 370 |
ServiceBusEndpoint: "--service-bus-endpoint--", |
| 371 |
StorageEndpointSuffix: "--storage-endpoint-suffix--", |
| 372 |
CosmosDBDNSSuffix: "--cosmos-db-dns-suffix--", |
| 373 |
MariaDBDNSSuffix: "--maria-db-dns-suffix--", |
| 374 |
MySQLDatabaseDNSSuffix: "--mysql-database-dns-suffix--", |
| 375 |
PostgresqlDatabaseDNSSuffix: "--postgresql-database-dns-suffix--", |
| 376 |
SQLDatabaseDNSSuffix: "--sql-database-dns-suffix--", |
| 377 |
TrafficManagerDNSSuffix: "--traffic-manager-dns-suffix--", |
| 378 |
KeyVaultDNSSuffix: "--key-vault-dns-suffix--", |
| 379 |
ServiceBusEndpointSuffix: "--service-bus-endpoint-suffix--", |
| 380 |
ServiceManagementVMDNSSuffix: "--asm-vm-dns-suffix--", |
| 381 |
ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--", |
| 382 |
ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--", |
| 383 |
ResourceIdentifiers: ResourceIdentifier{ |
| 384 |
Batch: batchResourceID, |
| 385 |
Datalake: datalakeResourceID, |
| 386 |
Graph: graphResourceID, |
| 387 |
KeyVault: keyvaultResourceID, |
| 388 |
OperationalInsights: opInsightsResourceID, |
| 389 |
OSSRDBMS: ossRDBMSResourceID, |
| 390 |
CosmosDB: cosmosDBResourceID, |
| 391 |
}, |
| 392 |
} |
| 393 |
|
| 394 |
bytes, err := json.Marshal(env) |
| 395 |
if err != nil { |
| 396 |
t.Fatalf("failed to marshal: %s", err) |
| 397 |
} |
| 398 |
|
| 399 |
testSubject := Environment{} |
| 400 |
err = json.Unmarshal(bytes, &testSubject) |
| 401 |
if err != nil { |
| 402 |
t.Fatalf("failed to unmarshal: %s", err) |
| 403 |
} |
| 404 |
|
| 405 |
if env.Name != testSubject.Name { |
| 406 |
t.Errorf("Expected Name to be %q, but got %q", env.Name, testSubject.Name) |
| 407 |
} |
| 408 |
if env.ManagementPortalURL != testSubject.ManagementPortalURL { |
| 409 |
t.Errorf("Expected ManagementPortalURL to be %q, but got %q", env.ManagementPortalURL, testSubject.ManagementPortalURL) |
| 410 |
} |
| 411 |
if env.PublishSettingsURL != testSubject.PublishSettingsURL { |
| 412 |
t.Errorf("Expected PublishSettingsURL to be %q, but got %q", env.PublishSettingsURL, testSubject.PublishSettingsURL) |
| 413 |
} |
| 414 |
if env.ServiceManagementEndpoint != testSubject.ServiceManagementEndpoint { |
| 415 |
t.Errorf("Expected ServiceManagementEndpoint to be %q, but got %q", env.ServiceManagementEndpoint, testSubject.ServiceManagementEndpoint) |
| 416 |
} |
| 417 |
if env.ResourceManagerEndpoint != testSubject.ResourceManagerEndpoint { |
| 418 |
t.Errorf("Expected ResourceManagerEndpoint to be %q, but got %q", env.ResourceManagerEndpoint, testSubject.ResourceManagerEndpoint) |
| 419 |
} |
| 420 |
if env.ActiveDirectoryEndpoint != testSubject.ActiveDirectoryEndpoint { |
| 421 |
t.Errorf("Expected ActiveDirectoryEndpoint to be %q, but got %q", env.ActiveDirectoryEndpoint, testSubject.ActiveDirectoryEndpoint) |
| 422 |
} |
| 423 |
if env.GalleryEndpoint != testSubject.GalleryEndpoint { |
| 424 |
t.Errorf("Expected GalleryEndpoint to be %q, but got %q", env.GalleryEndpoint, testSubject.GalleryEndpoint) |
| 425 |
} |
| 426 |
if env.ServiceBusEndpoint != testSubject.ServiceBusEndpoint { |
| 427 |
t.Errorf("Expected ServiceBusEnpoint to be %q, but got %q", env.ServiceBusEndpoint, testSubject.ServiceBusEndpoint) |
| 428 |
} |
| 429 |
if env.KeyVaultEndpoint != testSubject.KeyVaultEndpoint { |
| 430 |
t.Errorf("Expected KeyVaultEndpoint to be %q, but got %q", env.KeyVaultEndpoint, testSubject.KeyVaultEndpoint) |
| 431 |
} |
| 432 |
if env.GraphEndpoint != testSubject.GraphEndpoint { |
| 433 |
t.Errorf("Expected GraphEndpoint to be %q, but got %q", env.GraphEndpoint, testSubject.GraphEndpoint) |
| 434 |
} |
| 435 |
if env.StorageEndpointSuffix != testSubject.StorageEndpointSuffix { |
| 436 |
t.Errorf("Expected StorageEndpointSuffix to be %q, but got %q", env.StorageEndpointSuffix, testSubject.StorageEndpointSuffix) |
| 437 |
} |
| 438 |
if env.CosmosDBDNSSuffix != testSubject.CosmosDBDNSSuffix { |
| 439 |
t.Errorf("Expected CosmosDBDNSSuffix to be %q, but got %q", env.CosmosDBDNSSuffix, testSubject.CosmosDBDNSSuffix) |
| 440 |
} |
| 441 |
if env.MariaDBDNSSuffix != testSubject.MariaDBDNSSuffix { |
| 442 |
t.Errorf("Expected MariaDBDNSSuffix to be %q, but got %q", env.MariaDBDNSSuffix, testSubject.MariaDBDNSSuffix) |
| 443 |
} |
| 444 |
if env.MySQLDatabaseDNSSuffix != testSubject.MySQLDatabaseDNSSuffix { |
| 445 |
t.Errorf("Expected MySQLDatabaseDNSSuffix to be %q, but got %q", env.MySQLDatabaseDNSSuffix, testSubject.MySQLDatabaseDNSSuffix) |
| 446 |
} |
| 447 |
if env.PostgresqlDatabaseDNSSuffix != testSubject.PostgresqlDatabaseDNSSuffix { |
| 448 |
t.Errorf("Expected PostgresqlDatabaseDNSSuffix to be %q, but got %q", env.PostgresqlDatabaseDNSSuffix, testSubject.PostgresqlDatabaseDNSSuffix) |
| 449 |
} |
| 450 |
if env.SQLDatabaseDNSSuffix != testSubject.SQLDatabaseDNSSuffix { |
| 451 |
t.Errorf("Expected SQLDatabaseDNSSuffix to be %q, but got %q", env.SQLDatabaseDNSSuffix, testSubject.SQLDatabaseDNSSuffix) |
| 452 |
} |
| 453 |
if env.TrafficManagerDNSSuffix != testSubject.TrafficManagerDNSSuffix { |
| 454 |
t.Errorf("Expected TrafficManagerDNSSuffix to be %q, but got %q", env.TrafficManagerDNSSuffix, testSubject.TrafficManagerDNSSuffix) |
| 455 |
} |
| 456 |
if env.KeyVaultDNSSuffix != testSubject.KeyVaultDNSSuffix { |
| 457 |
t.Errorf("Expected KeyVaultDNSSuffix to be %q, but got %q", env.KeyVaultDNSSuffix, testSubject.KeyVaultDNSSuffix) |
| 458 |
} |
| 459 |
if env.ServiceBusEndpointSuffix != testSubject.ServiceBusEndpointSuffix { |
| 460 |
t.Errorf("Expected ServiceBusEndpointSuffix to be %q, but got %q", env.ServiceBusEndpointSuffix, testSubject.ServiceBusEndpointSuffix) |
| 461 |
} |
| 462 |
if env.ServiceManagementVMDNSSuffix != testSubject.ServiceManagementVMDNSSuffix { |
| 463 |
t.Errorf("Expected ServiceManagementVMDNSSuffix to be %q, but got %q", env.ServiceManagementVMDNSSuffix, testSubject.ServiceManagementVMDNSSuffix) |
| 464 |
} |
| 465 |
if env.ResourceManagerVMDNSSuffix != testSubject.ResourceManagerVMDNSSuffix { |
| 466 |
t.Errorf("Expected ResourceManagerVMDNSSuffix to be %q, but got %q", env.ResourceManagerVMDNSSuffix, testSubject.ResourceManagerVMDNSSuffix) |
| 467 |
} |
| 468 |
if env.ContainerRegistryDNSSuffix != testSubject.ContainerRegistryDNSSuffix { |
| 469 |
t.Errorf("Expected ContainerRegistryDNSSuffix to be %q, but got %q", env.ContainerRegistryDNSSuffix, testSubject.ContainerRegistryDNSSuffix) |
| 470 |
} |
| 471 |
if env.ResourceIdentifiers.Batch != testSubject.ResourceIdentifiers.Batch { |
| 472 |
t.Errorf("Expected ResourceIdentifiers.Batch to be %q, but got %q", env.ResourceIdentifiers.Batch, testSubject.ResourceIdentifiers.Batch) |
| 473 |
} |
| 474 |
if env.ResourceIdentifiers.Datalake != testSubject.ResourceIdentifiers.Datalake { |
| 475 |
t.Errorf("Expected ResourceIdentifiers.Datalake to be %q, but got %q", env.ResourceIdentifiers.Datalake, testSubject.ResourceIdentifiers.Datalake) |
| 476 |
} |
| 477 |
if env.ResourceIdentifiers.Graph != testSubject.ResourceIdentifiers.Graph { |
| 478 |
t.Errorf("Expected ResourceIdentifiers.Graph to be %q, but got %q", env.ResourceIdentifiers.Graph, testSubject.ResourceIdentifiers.Graph) |
| 479 |
} |
| 480 |
if env.ResourceIdentifiers.KeyVault != testSubject.ResourceIdentifiers.KeyVault { |
| 481 |
t.Errorf("Expected ResourceIdentifiers.KeyVault to be %q, but got %q", env.ResourceIdentifiers.KeyVault, testSubject.ResourceIdentifiers.KeyVault) |
| 482 |
} |
| 483 |
if env.ResourceIdentifiers.OperationalInsights != testSubject.ResourceIdentifiers.OperationalInsights { |
| 484 |
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be %q, but got %q", env.ResourceIdentifiers.OperationalInsights, testSubject.ResourceIdentifiers.OperationalInsights) |
| 485 |
} |
| 486 |
if env.ResourceIdentifiers.OSSRDBMS != testSubject.ResourceIdentifiers.OSSRDBMS { |
| 487 |
t.Errorf("Expected ResourceIdentifiers.OSSRDBMS to be %q, but got %q", env.ResourceIdentifiers.OSSRDBMS, testSubject.ResourceIdentifiers.OSSRDBMS) |
| 488 |
} |
| 489 |
if env.ResourceIdentifiers.CosmosDB != testSubject.ResourceIdentifiers.CosmosDB { |
| 490 |
t.Errorf("Expected ResourceIdentifiers.CosmosDB to be %q, but got %q", env.ResourceIdentifiers.CosmosDB, testSubject.ResourceIdentifiers.CosmosDB) |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
func TestSetEnvironment(t *testing.T) { |
| 495 |
const testEnvName = "testenvironment" |
| 496 |
if _, err := EnvironmentFromName(testEnvName); err == nil { |
| 497 |
t.Fatal("expected non-nil error") |
| 498 |
} |
| 499 |
testEnv := Environment{Name: testEnvName} |
| 500 |
SetEnvironment(testEnvName, testEnv) |
| 501 |
result, err := EnvironmentFromName(testEnvName) |
| 502 |
if err != nil { |
| 503 |
t.Fatalf("failed to get custom environment: %v", err) |
| 504 |
} |
| 505 |
if testEnv != result { |
| 506 |
t.Fatalf("expected %v, got %v", testEnv, result) |
| 507 |
} |
| 508 |
} |