// Test Command REST call when service is locked.
Test Command REST call when service is locked.
// Test Command REST call when service is locked .
func TestCommandServiceLocked(t *testing.T) {
	lc := logger.NewClient("command_test", false, "./command_test.log", "DEBUG")
	common.LoggingClient = lc
	common.ServiceLocked = true
	common.ServiceName = deviceCommandTest
	r := InitRestRoutes()
	req := httptest.NewRequest("GET", fmt.Sprintf("%s/%s/%s", clients.ApiDeviceRoute, "nil", "nil"), nil)
	req = mux.SetURLVars(req, map[string]string{"deviceId": "nil", "cmd": "nil"})
	rr := httptest.NewRecorder()
	r.ServeHTTP(rr, req)
	if status := rr.Code; status != http.StatusLocked {
		t.Errorf("ServiceLocked: handler returned wrong status code: got %v want %v",
			status, http.StatusLocked)
	}
	body := strings.TrimSpace(rr.Body.String())
	expected := deviceCommandTest + " is locked; GET " + clients.ApiDeviceRoute + "/nil/nil"
	if body != expected {
		t.Errorf("ServiceLocked: handler returned wrong body:\nexpected: %s\ngot:      %s", expected, body)
	}
}
func TestCommandServiceLocked ( t * testing . T ) { lc := logger . NewClient ( " " , false , " " , " " ) common . LoggingClient = lc common . ServiceLocked = true common . ServiceName = deviceCommandTest r := InitRestRoutes ( ) req := httptest . NewRequest ( " " , fmt . Sprintf ( " " , clients . ApiDeviceRoute , " " , " " ) , nil ) req = mux . SetURLVars ( req , map [ string ] string { " " : " " , " " : " " } ) rr := httptest . NewRecorder ( ) r . ServeHTTP ( rr , req ) if status := rr . Code ; status != http . StatusLocked { t . Errorf ( " " , status , http . StatusLocked ) } body := strings . TrimSpace ( rr . Body . String ( ) ) expected := deviceCommandTest + " " + clients . ApiDeviceRoute + " " if body != expected { t . Errorf ( " \n \n " , expected , body ) } }
Test Command REST call when service is locked.
Test Command REST call when service is locked .