(t *testing.T)
| 84 | func (e *nodeAPIError) Error() string { return e.msg } |
| 85 | |
| 86 | func 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 | } |
nothing calls this directly
no test coverage detected