tarakan-client/internal/api/device_auth_test.go
Maxfield Luke 58b29a7f84
Some checks failed
CI and releases / Test and vet (push) Failing after 1s
CI and releases / Build release binaries (push) Has been skipped
CI and releases / Publish GitHub release (push) Has been skipped
Initial commit on Forgejo
Fresh repository history for elektrine/tarakan-client hosted at
https://git.elektrine.com/elektrine/tarakan-client.
2026-07-29 04:56:36 -04:00

30 lines
810 B
Go

package api
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"testing"
)
func TestDeviceAuthorizationMapsPendingResponse(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "" {
t.Fatalf("public request included an Authorization header")
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(`{"error":"authorization_pending"}`))
}))
defer server.Close()
client, err := NewPublic(server.URL, nil)
if err != nil {
t.Fatal(err)
}
_, err = client.ExchangeDeviceAuthorization(context.Background(), "device-code")
if !errors.Is(err, ErrAuthorizationPending) {
t.Fatalf("err = %v, want ErrAuthorizationPending", err)
}
}