(t *testing.T)
| 141 | } |
| 142 | |
| 143 | func 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 | |
| 173 | func TestUserSupportsMultipleProtocols(t *testing.T) { |
| 174 | mux, ibStore := setupTestMux(t, map[string]func(body any) (json.RawMessage, error){ |
nothing calls this directly
no test coverage detected