-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.go
More file actions
65 lines (58 loc) · 2.27 KB
/
Copy pathcli_test.go
File metadata and controls
65 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
"github.com/aviorstudio/termcade/internal/registry"
)
func TestAddAcceptsMarketplaceIDsOnly(t *testing.T) {
for _, input := range []string{"game.tcade", "https://example.test/game.tcade", "./game.tcade"} {
err := cmdAdd([]string{input})
if err == nil || !strings.Contains(err.Error(), "dev install") {
t.Errorf("cmdAdd(%q) = %v, want dev-install guidance", input, err)
}
}
}
func TestExpiredSessionDoesNotPretendLibraryRemovalSucceeded(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
}))
t.Cleanup(srv.Close)
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
if err := registry.SaveSession(registry.Session{Registry: srv.URL, Token: "tcc_" + strings.Repeat("A", 43)}); err != nil {
t.Fatal(err)
}
err := syncLibraryRemove("aviorstudio", "tetris")
if err == nil || !strings.Contains(err.Error(), "session has expired") {
t.Fatalf("remove = %v, want expired-session error", err)
}
}
func TestMarketplaceAddRequestOrderIsStable(t *testing.T) {
// Guard the exact invariant independently of any later diagnostic request:
// choosing the game is durable before attempting to fill the local cache.
want := []string{"PUT /v1/library/aviorstudio/tetris", "GET /v1/games/aviorstudio/tetris/resolve"}
var got []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got = append(got, r.Method+" "+r.URL.Path)
if r.Method == http.MethodPut {
w.WriteHeader(http.StatusNoContent)
return
}
http.Error(w, `{"message":"stop"}`, http.StatusBadGateway)
}))
t.Cleanup(srv.Close)
_ = addFromRegistry(®istry.Session{Registry: srv.URL, Token: "session"}, "aviorstudio/tetris")
if !slices.Equal(got, want) {
t.Fatalf("requests = %v, want %v", got, want)
}
}
func TestPublishEnvironmentAcceptsOnlyPublishKeys(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("TERMCADE_TOKEN", "tcc_"+strings.Repeat("A", 43))
err := cmdPublish([]string{"https://github.com/acme/game", "v1.0.0", "game.tcade"})
if err == nil || !strings.Contains(err.Error(), "scoped publish key") {
t.Fatalf("CLI credential used as publishing-key environment default: %v", err)
}
}