package github import ( "context" "encoding/json" "net/http" "testing" ) func TestGetAuthenticatedUser_HappyPath(t *testing.T) { c := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { t.Errorf("expected GET, got %s", r.Method) } if r.URL.Path != "/user" { t.Errorf("unexpected path: %s", r.URL.Path) } if r.Header.Get("Authorization") != "Bearer test-token" { t.Errorf("unexpected auth header: %s", r.Header.Get("Authorization")) } json.NewEncoder(w).Encode(map[string]string{"login": "review-bot"}) }) login, err := c.GetAuthenticatedUser(context.Background()) if err != nil { t.Fatalf("unexpected error: %v", err) } if login != "review-bot" { t.Errorf("expected login 'review-bot', got %q", login) } } func TestGetAuthenticatedUser_401(t *testing.T) { c := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(401) w.Write([]byte(`{"message":"Bad credentials"}`)) }) _, err := c.GetAuthenticatedUser(context.Background()) if err == nil { t.Fatal("expected error for 401") } if !IsUnauthorized(err) { t.Errorf("expected IsUnauthorized=true, got error: %v", err) } }