MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestCreateUserAutoGeneratesID

Function TestCreateUserAutoGeneratesID

internal/serverapi/users_test.go:143–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestCreateUserAutoGeneratesID(t *testing.T) {
144 nodeStore := nodes.NewMemoryStore()
145 _, _ = nodeStore.Upsert(nodes.Node{
146 ID: "node-1",
147 Name: "node 1",
148 BaseURL: "http://node.test",
149 })
150
151 baseAPI := New(nodeStore)
152 userAPI := newUserAPI(users.NewMemoryStore(), nodeStore, inbounds.NewMemoryStore(), nil, baseAPI, nil, jobs.ApplyOptions{}, nil)
153 mux := http.NewServeMux()
154 userAPI.Register(mux)
155
156 body := []byte(`{"username":"alice"}`)
157 rec := httptest.NewRecorder()
158 req := httptest.NewRequest(http.MethodPost, "/v1/users", bytes.NewReader(body))
159 mux.ServeHTTP(rec, req)
160 if rec.Code != http.StatusOK {
161 t.Fatalf("create user status = %d body=%s", rec.Code, rec.Body.String())
162 }
163
164 var out users.User
165 if err := json.NewDecoder(rec.Body).Decode(&out); err != nil {
166 t.Fatalf("decode user: %v", err)
167 }
168 if out.ID == "" {
169 t.Fatal("expected generated user id")
170 }
171}
172
173func TestUserSupportsMultipleProtocols(t *testing.T) {
174 mux, ibStore := setupTestMux(t, map[string]func(body any) (json.RawMessage, error){

Callers

nothing calls this directly

Calls 9

UpsertMethod · 0.95
NewMemoryStoreFunction · 0.92
NewMemoryStoreFunction · 0.92
NewMemoryStoreFunction · 0.92
newUserAPIFunction · 0.85
ServeHTTPMethod · 0.80
NewFunction · 0.70
RegisterMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected