Skip to content

Commit 3be7ee8

Browse files
committed
test: add API error branch and edge case tests (81% → 84% api coverage)
1 parent 50990f4 commit 3be7ee8

2 files changed

Lines changed: 431 additions & 0 deletions

File tree

internal/api/client_mutations_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,51 @@ func TestUpdateServiceNotFound(t *testing.T) {
556556
}
557557
}
558558

559+
func TestUpdateServiceForbidden(t *testing.T) {
560+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
561+
w.WriteHeader(http.StatusForbidden)
562+
}))
563+
defer server.Close()
564+
565+
client := newTestClient(t, server.URL)
566+
_, err := client.UpdateService(context.Background(), "svc-1", map[string]string{"name": "x"})
567+
if err == nil {
568+
t.Fatal("expected error for 403")
569+
}
570+
if !strings.Contains(err.Error(), "access denied") {
571+
t.Errorf("error = %q, want 'access denied'", err.Error())
572+
}
573+
}
574+
575+
func TestUpdateServiceUnauthorized(t *testing.T) {
576+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
577+
w.WriteHeader(http.StatusUnauthorized)
578+
}))
579+
defer server.Close()
580+
581+
client := newTestClient(t, server.URL)
582+
_, err := client.UpdateService(context.Background(), "svc-1", map[string]string{"name": "x"})
583+
if err == nil {
584+
t.Fatal("expected error for 401")
585+
}
586+
if !strings.Contains(err.Error(), "invalid API token") {
587+
t.Errorf("error = %q, want 'invalid API token'", err.Error())
588+
}
589+
}
590+
591+
func TestUpdateServiceServerError(t *testing.T) {
592+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
593+
w.WriteHeader(http.StatusInternalServerError)
594+
}))
595+
defer server.Close()
596+
597+
client := newTestClient(t, server.URL)
598+
_, err := client.UpdateService(context.Background(), "svc-1", map[string]string{"name": "x"})
599+
if err == nil {
600+
t.Fatal("expected error for 500")
601+
}
602+
}
603+
559604
// --- CreateTeam ---
560605

561606
func TestCreateTeam(t *testing.T) {

0 commit comments

Comments
 (0)