(t *testing.T)
| 355 | } |
| 356 | |
| 357 | func TestUpdateNodeProperties(t *testing.T) { |
| 358 | f, err := os.CreateTemp("", t.Name()) |
| 359 | assert.NoError(t, err) |
| 360 | assert.NotNil(t, f) |
| 361 | fmt.Println("-->tempfile", f.Name()) |
| 362 | defer os.RemoveAll(f.Name()) |
| 363 | |
| 364 | s, err := store.NewBoltHold(f.Name()) |
| 365 | assert.NoError(t, err) |
| 366 | assert.NotNil(t, s) |
| 367 | |
| 368 | ss, err := NewNode(s) |
| 369 | assert.NoError(t, err) |
| 370 | assert.NotNil(t, ss) |
| 371 | |
| 372 | router := routing.New() |
| 373 | router.Put("/node/properties", utils.Wrapper(ss.UpdateNodeProperties)) |
| 374 | go fasthttp.ListenAndServe(":50022", router.HandleRequest) |
| 375 | time.Sleep(100 * time.Millisecond) |
| 376 | |
| 377 | delta := map[string]interface{}{} |
| 378 | data, _ := json.Marshal(delta) |
| 379 | client := &fasthttp.Client{} |
| 380 | req := fasthttp.AcquireRequest() |
| 381 | req.SetBody(data) |
| 382 | resp := fasthttp.AcquireResponse() |
| 383 | url := fmt.Sprintf("%s%s", "http://127.0.0.1:50022", "/node/properties") |
| 384 | req.SetRequestURI(url) |
| 385 | req.Header.SetMethod("PUT") |
| 386 | err = client.Do(req, resp) |
| 387 | assert.NoError(t, err) |
| 388 | assert.Equal(t, resp.StatusCode(), 200) |
| 389 | |
| 390 | report := v1.Report{ |
| 391 | KeyNodeProps: map[string]interface{}{ |
| 392 | "a": "1", |
| 393 | }, |
| 394 | } |
| 395 | delta = map[string]interface{}{ |
| 396 | "a": "2", |
| 397 | "b": "3", |
| 398 | } |
| 399 | expect := map[string]interface{}{ |
| 400 | "a": "2", |
| 401 | "b": "3", |
| 402 | } |
| 403 | _, err = ss.Report(report, true) |
| 404 | assert.NoError(t, err) |
| 405 | |
| 406 | data, _ = json.Marshal(delta) |
| 407 | req2 := fasthttp.AcquireRequest() |
| 408 | resp2 := fasthttp.AcquireResponse() |
| 409 | req2.SetRequestURI(url) |
| 410 | req2.SetBody(data) |
| 411 | req2.Header.SetMethod("PUT") |
| 412 | err = client.Do(req2, resp2) |
| 413 | assert.NoError(t, err) |
| 414 | assert.Equal(t, resp2.StatusCode(), 200) |
nothing calls this directly
no test coverage detected