okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

dawnadd colab extension47735ec

main
1.7 KiB64 linesraw
1package daemon
2
3import (
4	"encoding/json"
5	"net/http"
6	"testing"
7)
8
9func TestSignInListPopulatesKind(t *testing.T) {
10	conn := controlledConnection(t, func(w http.ResponseWriter, r *http.Request) {
11		if r.URL.Path != "/auth" {
12			t.Errorf("unexpected path: %s", r.URL.Path)
13		}
14		_ = json.NewEncoder(w).Encode(map[string]any{
15			"providers": []map[string]any{
16				{
17					"id":     "claude",
18					"label":  "Claude",
19					"detail": "console billing",
20					"kind":   "model",
21					"flows":  []string{"browser"},
22					"fields": []any{},
23				},
24				{
25					"id":     "colab",
26					"label":  "Google Colab",
27					"detail": "service account",
28					"kind":   "service",
29					"flows":  []string{"browser"},
30					"fields": []any{},
31				},
32			},
33			"accounts": []map[string]any{
34				{
35					"id":                   "acc-model",
36					"provider":             "claude",
37					"label":                "user@example.com",
38					"detail":               "pro plan",
39					"kind":                 "model",
40					"selected_by_profiles": []string{"claude"},
41				},
42				{
43					"id":                   "acc-service",
44					"provider":             "colab",
45					"label":                "service@example.com",
46					"detail":               "colab tokens",
47					"kind":                 "service",
48					"selected_by_profiles": []string{},
49				},
50			},
51		})
52	})
53
54	list, err := SignInList(t.Context(), conn)
55	if err != nil {
56		t.Fatalf("SignInList failed: %v", err)
57	}
58	if len(list.Logins) != 2 || list.Logins[0].Kind != "model" || list.Logins[1].Kind != "service" {
59		t.Fatalf("unexpected logins kind: %+v", list.Logins)
60	}
61	if len(list.Accounts) != 2 || list.Accounts[0].Kind != "model" || list.Accounts[1].Kind != "service" {
62		t.Fatalf("unexpected accounts kind: %+v", list.Accounts)
63	}
64}