Skip to content

Commit 32a0d4a

Browse files
committed
fix: enhance error message validation in TestEnsureLoggedIn function
1 parent c1c7973 commit 32a0d4a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,8 @@ func TestEnsureLoggedIn(t *testing.T) {
12131213
serverErr error
12141214
wantErr bool
12151215
wantCode string
1216-
wantPassth bool // expect the original error to be returned as-is
1216+
wantMsg string // substring expected in the error message
1217+
wantPassth bool // expect the original error to be returned as-is
12171218
}{
12181219
{
12191220
name: "success returns nil",
@@ -1225,12 +1226,20 @@ func TestEnsureLoggedIn(t *testing.T) {
12251226
serverErr: status.Error(codes.Unauthenticated, "not logged in, run `azd auth login`"),
12261227
wantErr: true,
12271228
wantCode: exterrors.CodeNotLoggedIn,
1229+
wantMsg: "not logged in",
12281230
},
12291231
{
12301232
name: "unauthenticated preserves server message",
12311233
serverErr: status.Error(codes.Unauthenticated, "token expired"),
12321234
wantErr: true,
12331235
wantCode: exterrors.CodeNotLoggedIn,
1236+
wantMsg: "token expired",
1237+
},
1238+
{
1239+
name: "context canceled is propagated",
1240+
serverErr: context.Canceled,
1241+
wantErr: true,
1242+
wantPassth: true,
12341243
},
12351244
{
12361245
name: "gRPC cancelled is propagated",
@@ -1293,6 +1302,9 @@ func TestEnsureLoggedIn(t *testing.T) {
12931302
if localErr.Code != tt.wantCode {
12941303
t.Errorf("code = %q, want %q", localErr.Code, tt.wantCode)
12951304
}
1305+
if tt.wantMsg != "" && !strings.Contains(localErr.Message, tt.wantMsg) {
1306+
t.Errorf("message = %q, want it to contain %q", localErr.Message, tt.wantMsg)
1307+
}
12961308
})
12971309
}
12981310
}

0 commit comments

Comments
 (0)