@@ -24,14 +24,15 @@ import (
2424)
2525
2626func TestConfigDefaulting (t * testing.T ) {
27- expectedCompartmentOCID := "ocid1.compartment.oc1..aaaaaaaa3um2atybwhder4qttfhgon4j3hcxgmsvnyvx4flfjyewkkwfzwnq"
27+ expectedCompartmentID := "ocid1.compartment.oc1..aaaaaaaa3um2atybwhder4qttfhgon4j3hcxgmsvnyvx4flfjyewkkwfzwnq"
2828 expectedRegion := "us-phoenix-1"
2929 expectedRegionKey := "phx"
3030
3131 cfg := & Config {metadata : metadata .NewMock (
3232 & metadata.InstanceMetadata {
33- CompartmentOCID : expectedCompartmentOCID ,
34- Region : expectedRegionKey , // instance metadata API only returns the region key
33+ CompartmentID : expectedCompartmentID ,
34+ CanonicalRegionName : expectedRegion ,
35+ Region : expectedRegionKey , // instance metadata API only returns the region key
3536 },
3637 )}
3738
@@ -43,59 +44,13 @@ func TestConfigDefaulting(t *testing.T) {
4344 if cfg .Auth .Region != expectedRegion {
4445 t .Fatalf ("Expected cfg.Region = %q, got %q" , cfg .Auth .Region , expectedRegion )
4546 }
47+
4648 if cfg .Auth .RegionKey != expectedRegionKey {
4749 t .Fatalf ("Expected cfg.RegionKey = %q, got %q" , cfg .Auth .RegionKey , expectedRegionKey )
4850 }
4951
50- if cfg .Auth .CompartmentID != expectedCompartmentOCID {
51- t .Fatalf ("Expected cfg.CompartmentOCID = %q, got %q" , cfg .Auth .CompartmentID , expectedCompartmentOCID )
52- }
53- }
54-
55- func TestConfigSetRegion (t * testing.T ) {
56- var testCases = []struct {
57- in string
58- region string
59- shortRegion string
60- shouldErr bool
61- }{
62- {"us-phoenix-1" , "us-phoenix-1" , "phx" , false },
63- {"US-PHOENIX-1" , "us-phoenix-1" , "phx" , false },
64- {"phx" , "us-phoenix-1" , "phx" , false },
65- {"PHX" , "us-phoenix-1" , "phx" , false },
66-
67- {"us-ashburn-1" , "us-ashburn-1" , "iad" , false },
68- {"US-ASHBURN-1" , "us-ashburn-1" , "iad" , false },
69- {"iad" , "us-ashburn-1" , "iad" , false },
70- {"IAD" , "us-ashburn-1" , "iad" , false },
71-
72- {"eu-frankfurt-1" , "eu-frankfurt-1" , "fra" , false },
73- {"EU-FRANKFURT-1" , "eu-frankfurt-1" , "fra" , false },
74- {"fra" , "eu-frankfurt-1" , "fra" , false },
75- {"FRA" , "eu-frankfurt-1" , "fra" , false },
76-
77- // error cases
78- {"us-east" , "" , "" , true },
79- {"" , "" , "" , true },
80- }
81-
82- for _ , tt := range testCases {
83- t .Run (tt .in , func (t * testing.T ) {
84- cfg := & Config {}
85- err := cfg .setRegionFields (tt .in )
86- if err != nil {
87- if ! tt .shouldErr {
88- t .Errorf ("SetRegionFields(%q) unexpected error: %v" , tt .in , err )
89- }
90- }
91-
92- if cfg .Auth .Region != tt .region {
93- t .Errorf ("SetRegionFields(%q) => {Region: %q}; want {Region: %q}" , tt .in , cfg .Auth .Region , tt .region )
94- }
95- if cfg .Auth .RegionKey != tt .shortRegion {
96- t .Errorf ("SetRegionFields(%q) => {RegionShortName: %q}; want {RegionShortName: %q}" , tt .in , cfg .Auth .RegionKey , tt .shortRegion )
97- }
98- })
52+ if cfg .Auth .CompartmentID != expectedCompartmentID {
53+ t .Fatalf ("Expected cfg.CompartmentID = %q, got %q" , cfg .Auth .CompartmentID , expectedCompartmentID )
9954 }
10055}
10156
0 commit comments