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

Function TestCreateNodeAutoGeneratesID

internal/serverapi/api_test.go:86–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84func (e *nodeAPIError) Error() string { return e.msg }
85
86func TestCreateNodeAutoGeneratesID(t *testing.T) {
87 store := nodes.NewMemoryStore()
88 api := New(store)
89 mux := http.NewServeMux()
90 api.Register(mux)
91
92 rec := httptest.NewRecorder()
93 req := httptest.NewRequest(http.MethodPost, "/v1/nodes", bytes.NewReader([]byte(`{"name":"node 1","base_url":"http://node.test"}`)))
94 mux.ServeHTTP(rec, req)
95 if rec.Code != http.StatusOK {
96 t.Fatalf("create node status = %d body=%s", rec.Code, rec.Body.String())
97 }
98
99 var out nodes.Node
100 if err := json.NewDecoder(rec.Body).Decode(&out); err != nil {
101 t.Fatalf("decode node: %v", err)
102 }
103 if out.ID == "" {
104 t.Fatal("expected generated node id")
105 }
106}

Callers

nothing calls this directly

Calls 5

NewMemoryStoreFunction · 0.92
ServeHTTPMethod · 0.80
NewFunction · 0.70
RegisterMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected