// TestCommandNoDevice tests the command REST call when the given deviceId doesn't
// specify an existing device.
TestCommandNoDevice tests the command REST call when the given deviceId doesn't
specify an existing device.
// TestCommandNoDevice tests the command REST call when the given deviceId doesn ' t // specify an existing device .
func TestCommandNoDevice(t *testing.T) {
	lc := logger.NewClient("command_test", false, "./command_test.log", "DEBUG")
	common.LoggingClient = lc
	common.ServiceLocked = false
	common.ValueDescriptorClient = &mock.ValueDescriptorMock{}
	r := InitRestRoutes()
	req := httptest.NewRequest("GET", fmt.Sprintf("%s/%s/%s", clients.ApiDeviceRoute, badDeviceId, testCmd), nil)
	req = mux.SetURLVars(req, map[string]string{"deviceId": badDeviceId, "cmd": testCmd})
	rr := httptest.NewRecorder()
	r.ServeHTTP(rr, req)
	if status := rr.Code; status != http.StatusNotFound {
		t.Errorf("NoDevice: handler returned wrong status code: got %v want %v",
			status, http.StatusNotFound)
	}
	body := strings.TrimSpace(rr.Body.String())
	expected := "Device: " + badDeviceId + " not found; GET " + clients.ApiDeviceRoute + "/" + badDeviceId + "/" + testCmd
	if body != expected {
		t.Errorf("No Device: handler returned wrong body:\nexpected: %s\ngot:      %s", expected, body)
	}
}
func TestCommandNoDevice ( t * testing . T ) { lc := logger . NewClient ( " " , false , " " , " " ) common . LoggingClient = lc common . ServiceLocked = false common . ValueDescriptorClient = & mock . ValueDescriptorMock { } r := InitRestRoutes ( ) req := httptest . NewRequest ( " " , fmt . Sprintf ( " " , clients . ApiDeviceRoute , badDeviceId , testCmd ) , nil ) req = mux . SetURLVars ( req , map [ string ] string { " " : badDeviceId , " " : testCmd } ) rr := httptest . NewRecorder ( ) r . ServeHTTP ( rr , req ) if status := rr . Code ; status != http . StatusNotFound { t . Errorf ( " " , status , http . StatusNotFound ) } body := strings . TrimSpace ( rr . Body . String ( ) ) expected := " " + badDeviceId + " " + clients . ApiDeviceRoute + " " + badDeviceId + " " + testCmd if body != expected { t . Errorf ( " \n \n " , expected , body ) } }
TestCommandNoDevice tests the command REST call when the given deviceId doesn't
specify an existing device.
TestCommandNoDevice tests the command REST call when the given deviceId doesn ' t specify an existing device .