You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 22, 2025. It is now read-only.
fakebody=bytes.NewReader([]byte(`{"123, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
211
-
r=httptest.NewRequest("PUT", "localhost:8670/Comfortstat/Set%20Values/MinPrice", fakebody) // simulating a put request from a user to update the min temp
212
-
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
210
+
fakebody=bytes.NewReader([]byte(`{"123, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
211
+
r=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/MinPrice", fakebody) // simulating a put request from a user to update the min temp
212
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
fakebody:=bytes.NewReader([]byte(`{"value": 2, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
264
-
r:=httptest.NewRequest("PUT", "localhost:8670/Comfortstat/Set%20Values/MaxPrice", fakebody) // simulating a put request from a user to update the min temp
265
-
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
263
+
fakebody:=bytes.NewReader([]byte(`{"value": 2, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
264
+
r:=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/MaxPrice", fakebody) // simulating a put request from a user to update the min temp
265
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
fakebody=bytes.NewReader([]byte(`{"123, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
279
-
r=httptest.NewRequest("PUT", "localhost:8670/Comfortstat/Set%20Values/MaxPrice", fakebody) // simulating a put request from a user to update the min temp
280
-
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
278
+
fakebody=bytes.NewReader([]byte(`{"123, "unit": "SEK", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
279
+
r=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/MaxPrice", fakebody) // simulating a put request from a user to update the min temp
280
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
fakebody:=bytes.NewReader([]byte(`{"value": 0, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
335
-
r:=httptest.NewRequest("PUT", "localhost:8670/Comfortstat/Set%20Values/DesiredTemp", fakebody)// simulating a put request from a user to update the min temp
336
-
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
334
+
fakebody:=bytes.NewReader([]byte(`{"value": 0, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
335
+
r:=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/DesiredTemp", fakebody) // simulating a put request from a user to update the min temp
336
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
fakebody=bytes.NewReader([]byte(`{"123, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
352
-
r=httptest.NewRequest("PUT", "localhost:8670/Comfortstat/Set%20Values/DesiredTemp", fakebody) // simulating a put request from a user to update the min temp
353
-
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
351
+
fakebody=bytes.NewReader([]byte(`{"123, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
352
+
r=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/DesiredTemp", fakebody) // simulating a put request from a user to update the min temp
353
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
t.Errorf("expected the status to be bad but got: %v", resp.StatusCode)
398
398
}
399
399
}
400
+
401
+
funcTestHttpSetUserTemp(t*testing.T) {
402
+
ua:=initTemplate().(*UnitAsset)
403
+
//Godd test case: PUT
404
+
405
+
// creates a fake request body with JSON data
406
+
w:=httptest.NewRecorder()
407
+
fakebody:=bytes.NewReader([]byte(`{"value": 0, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
408
+
r:=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/userTemp", fakebody) // simulating a put request from a user to update the min temp
409
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
410
+
goodStatusCode:=200
411
+
412
+
ua.httpSetUserTemp(w, r)
413
+
414
+
// save the rsponse and read the body
415
+
resp:=w.Result()
416
+
ifresp.StatusCode!=goodStatusCode {
417
+
t.Errorf("expected good status code: %v, got %v", goodStatusCode, resp.StatusCode)
418
+
}
419
+
420
+
//BAD case: PUT, if the fake body is formatted incorrectly
421
+
422
+
// creates a fake request body with JSON data
423
+
w=httptest.NewRecorder()
424
+
fakebody=bytes.NewReader([]byte(`{"123, "unit": "Celsius", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
425
+
r=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/userTemp", fakebody) // simulating a put request from a user to update the min temp
426
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
427
+
428
+
ua.httpSetUserTemp(w, r)
429
+
// save the rsponse and read the body
430
+
resp=w.Result()
431
+
ifresp.StatusCode==goodStatusCode {
432
+
t.Errorf("expected bad status code: %v, got %v", goodStatusCode, resp.StatusCode)
// calls the method and extracts the response and save is in resp for the upcoming tests
467
+
ua.httpSetUserTemp(w, r)
468
+
resp=w.Result()
469
+
ifresp.StatusCode!=http.StatusNotFound {
470
+
t.Errorf("expected the status to be bad but got: %v", resp.StatusCode)
471
+
}
472
+
}
473
+
474
+
funcTestHttpSetRegion(t*testing.T) {
475
+
ua:=initTemplate().(*UnitAsset)
476
+
//Godd test case: PUT
477
+
478
+
// creates a fake request body with JSON data
479
+
w:=httptest.NewRecorder()
480
+
fakebody:=bytes.NewReader([]byte(`{"value": 1, "unit": "RegionPoint", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
481
+
r:=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/Region", fakebody) // simulating a put request from a user to update the min temp
482
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
483
+
goodStatusCode:=200
484
+
485
+
ua.httpSetRegion(w, r)
486
+
487
+
// save the rsponse and read the body
488
+
resp:=w.Result()
489
+
ifresp.StatusCode!=goodStatusCode {
490
+
t.Errorf("expected good status code: %v, got %v", goodStatusCode, resp.StatusCode)
491
+
}
492
+
493
+
//BAD case: PUT, if the fake body is formatted incorrectly
494
+
495
+
// creates a fake request body with JSON data
496
+
w=httptest.NewRecorder()
497
+
fakebody=bytes.NewReader([]byte(`{"123, "unit": "RegionPoint", "version": "SignalA_v1.0"}`)) // converts the Jason data so it can be read
498
+
r=httptest.NewRequest("PUT", "http://localhost:8670/Comfortstat/Set%20Values/Region", fakebody) // simulating a put request from a user to update the min temp
499
+
r.Header.Set("Content-Type", "application/json") // basic setup to prevent the request to be rejected.
500
+
501
+
ua.httpSetRegion(w, r)
502
+
// save the rsponse and read the body
503
+
resp=w.Result()
504
+
ifresp.StatusCode==goodStatusCode {
505
+
t.Errorf("expected bad status code: %v, got %v", goodStatusCode, resp.StatusCode)
0 commit comments