MCPcopy
hub / github.com/baetyl/baetyl / TestGetNodeProperties

Function TestGetNodeProperties

node/node_test.go:291–355  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

289}
290
291func TestGetNodeProperties(t *testing.T) {
292 f, err := os.CreateTemp("", t.Name())
293 assert.NoError(t, err)
294 assert.NotNil(t, f)
295 fmt.Println("-->tempfile", f.Name())
296 defer os.RemoveAll(f.Name())
297
298 s, err := store.NewBoltHold(f.Name())
299 assert.NoError(t, err)
300 assert.NotNil(t, s)
301
302 ss, err := NewNode(s)
303 assert.NoError(t, err)
304 assert.NotNil(t, ss)
305
306 router := routing.New()
307 router.Get("/node/properties", utils.Wrapper(ss.GetNodeProperties))
308 go fasthttp.ListenAndServe(":50021", router.HandleRequest)
309 time.Sleep(100 * time.Millisecond)
310
311 client := &fasthttp.Client{}
312 req := fasthttp.AcquireRequest()
313 resp := fasthttp.AcquireResponse()
314 url := fmt.Sprintf("%s%s", "http://127.0.0.1:50021", "/node/properties")
315 req.SetRequestURI(url)
316 req.Header.SetMethod("GET")
317 err = client.Do(req, resp)
318 assert.NoError(t, err)
319 assert.Equal(t, resp.StatusCode(), 200)
320
321 desire := v1.Desire{
322 "nodeprops": map[string]interface{}{
323 "a": "1",
324 "b": "2",
325 },
326 }
327 _, err = ss.Desire(desire, true)
328 assert.NoError(t, err)
329 report := v1.Report{
330 "nodeprops": map[string]interface{}{
331 "a": "1",
332 "b": "3",
333 },
334 }
335 _, err = ss.Report(report, true)
336 assert.NoError(t, err)
337
338 req2 := fasthttp.AcquireRequest()
339 resp2 := fasthttp.AcquireResponse()
340 req2.SetRequestURI(url)
341 req2.Header.SetMethod("GET")
342 err = client.Do(req2, resp2)
343 assert.NoError(t, err)
344 assert.Equal(t, resp2.StatusCode(), 200)
345 // time unequal
346 var respNodeProps map[string]interface{}
347 json.Unmarshal(resp2.Body(), &respNodeProps)
348

Callers

nothing calls this directly

Calls 6

DesireMethod · 0.95
ReportMethod · 0.95
NewBoltHoldFunction · 0.92
WrapperFunction · 0.92
NewNodeFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected