Skip to content

Commit b790013

Browse files
committed
Separated test
1 parent 462d177 commit b790013

File tree

1 file changed

+62
-59
lines changed

1 file changed

+62
-59
lines changed

apps/confidential/confidential_test.go

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -164,73 +164,76 @@ func TestAcquireTokenByCredential(t *testing.T) {
164164
}
165165
}
166166

167-
func TestRegionAutoEnable(t *testing.T) {
167+
func TestRegionAutoEnable_EmptyRegion_EnvRegion(t *testing.T) {
168168
cred, err := NewCredFromSecret(fakeSecret)
169169
if err != nil {
170170
t.Fatal(err)
171171
}
172-
tests := []struct {
173-
region string
174-
envRegion string
175-
}{
176-
{
177-
region: "",
178-
envRegion: "envRegion",
179-
},
180-
{
181-
region: "region",
182-
envRegion: "envRegion",
183-
},
184-
{
185-
region: "DisableMsalForceRegion",
186-
envRegion: "envRegion",
187-
},
172+
173+
envRegion := "envRegion"
174+
err = os.Setenv("MSAL_FORCE_REGION", envRegion)
175+
if err != nil {
176+
t.Fatal(err)
188177
}
178+
defer os.Unsetenv("MSAL_FORCE_REGION")
189179

190-
for _, test := range tests {
191-
lmo := "login.microsoftonline.com"
192-
tenant := "tenant"
193-
mockClient := mock.Client{}
194-
if test.envRegion != "" {
195-
err := os.Setenv("MSAL_FORCE_REGION", test.envRegion)
196-
if err != nil {
197-
t.Fatal(err)
198-
}
199-
}
200-
var client Client
201-
if test.region != "" {
202-
client, err = New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient), WithAzureRegion(test.region))
203-
if err != nil {
204-
t.Fatal(err)
205-
}
206-
} else {
207-
client, err = New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient))
208-
if err != nil {
209-
t.Fatal(err)
210-
}
211-
}
180+
lmo := "login.microsoftonline.com"
181+
tenant := "tenant"
182+
mockClient := mock.Client{}
183+
client, err := New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient))
184+
if err != nil {
185+
t.Fatal(err)
186+
}
212187

213-
t.Cleanup(func() {
214-
os.Unsetenv("MSAL_FORCE_REGION")
215-
})
216-
if test.region == "" {
217-
if test.envRegion != "" {
218-
if client.base.AuthParams.AuthorityInfo.Region != test.envRegion {
219-
t.Fatalf("wanted %q, got %q", test.envRegion, client.base.AuthParams.AuthorityInfo.Region)
220-
}
221-
}
222-
} else {
223-
if test.region == "DisableMsalForceRegion" {
224-
if client.base.AuthParams.AuthorityInfo.Region != "" {
225-
t.Fatalf("wanted empty, got %q", client.base.AuthParams.AuthorityInfo.Region)
226-
}
227-
} else {
188+
if client.base.AuthParams.AuthorityInfo.Region != envRegion {
189+
t.Fatalf("wanted %q, got %q", envRegion, client.base.AuthParams.AuthorityInfo.Region)
190+
}
191+
}
228192

229-
if client.base.AuthParams.AuthorityInfo.Region != test.region {
230-
t.Fatalf("wanted %q, got %q", test.region, client.base.AuthParams.AuthorityInfo.Region)
231-
}
232-
}
233-
}
193+
func TestRegionAutoEnable_SpecifiedRegion_EnvRegion(t *testing.T) {
194+
cred, err := NewCredFromSecret(fakeSecret)
195+
if err != nil {
196+
t.Fatal(err)
197+
}
198+
199+
envRegion := "envRegion"
200+
err = os.Setenv("MSAL_FORCE_REGION", envRegion)
201+
if err != nil {
202+
t.Fatal(err)
203+
}
204+
defer os.Unsetenv("MSAL_FORCE_REGION")
205+
206+
lmo := "login.microsoftonline.com"
207+
tenant := "tenant"
208+
mockClient := mock.Client{}
209+
testRegion := "region"
210+
client, err := New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient), WithAzureRegion(testRegion))
211+
if err != nil {
212+
t.Fatal(err)
213+
}
214+
215+
if client.base.AuthParams.AuthorityInfo.Region != testRegion {
216+
t.Fatalf("wanted %q, got %q", testRegion, client.base.AuthParams.AuthorityInfo.Region)
217+
}
218+
}
219+
220+
func TestRegionAutoEnable_DisableMsalForceRegion(t *testing.T) {
221+
cred, err := NewCredFromSecret(fakeSecret)
222+
if err != nil {
223+
t.Fatal(err)
224+
}
225+
226+
lmo := "login.microsoftonline.com"
227+
tenant := "tenant"
228+
mockClient := mock.Client{}
229+
testRegion := "DisableMsalForceRegion"
230+
client, err := New(fmt.Sprintf(authorityFmt, lmo, tenant), fakeClientID, cred, WithHTTPClient(&mockClient), WithAzureRegion(testRegion))
231+
if err != nil {
232+
t.Fatal(err)
233+
}
234+
235+
if client.base.AuthParams.AuthorityInfo.Region != "" {
236+
t.Fatalf("wanted empty, got %q", client.base.AuthParams.AuthorityInfo.Region)
234237
}
235238
}
236239

0 commit comments

Comments
 (0)