diff --git a/api/api_test.go b/api/api_test.go index e7d0ce404..e8f4ffa53 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) func initTestAPI() *API { @@ -46,7 +46,7 @@ func TestStartWithoutDefaults(t *testing.T) { request, _ := http.NewRequest("GET", "/", nil) response := httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) } func TestRobeaux(t *testing.T) { @@ -55,22 +55,22 @@ func TestRobeaux(t *testing.T) { request, _ := http.NewRequest("GET", "/index.html", nil) response := httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) // js assets request, _ = http.NewRequest("GET", "/js/script.js", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) // css assets request, _ = http.NewRequest("GET", "/css/application.css", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) // unknown asset request, _ = http.NewRequest("GET", "/js/fake/file.js", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 404) + assert.Equal(t, 404, response.Code) } func TestIndex(t *testing.T) { @@ -80,8 +80,8 @@ func TestIndex(t *testing.T) { a.ServeHTTP(response, request) - gobottest.Assert(t, http.StatusMovedPermanently, response.Code) - gobottest.Assert(t, "/index.html", response.Header()["Location"][0]) + assert.Equal(t, response.Code, http.StatusMovedPermanently) + assert.Equal(t, response.Header()["Location"][0], "/index.html") } func TestMcp(t *testing.T) { @@ -92,8 +92,8 @@ func TestMcp(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Refute(t, body["MCP"].(map[string]interface{})["robots"], nil) - gobottest.Refute(t, body["MCP"].(map[string]interface{})["commands"], nil) + assert.NotNil(t, body["MCP"].(map[string]interface{})["robots"]) + assert.NotNil(t, body["MCP"].(map[string]interface{})["commands"]) } func TestMcpCommands(t *testing.T) { @@ -104,7 +104,7 @@ func TestMcpCommands(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["commands"], []interface{}{"TestFunction"}) + assert.Equal(t, []interface{}{"TestFunction"}, body["commands"]) } func TestExecuteMcpCommand(t *testing.T) { @@ -121,7 +121,7 @@ func TestExecuteMcpCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["result"], "hey Beep Boop") + assert.Equal(t, "hey Beep Boop", body.(map[string]interface{})["result"]) // unknown command request, _ = http.NewRequest("GET", @@ -133,7 +133,7 @@ func TestExecuteMcpCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["error"], "Unknown Command") + assert.Equal(t, "Unknown Command", body.(map[string]interface{})["error"]) } func TestRobots(t *testing.T) { @@ -144,7 +144,7 @@ func TestRobots(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, len(body["robots"].([]interface{})), 3) + assert.Equal(t, 3, len(body["robots"].([]interface{}))) } func TestRobot(t *testing.T) { @@ -157,14 +157,14 @@ func TestRobot(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["robot"].(map[string]interface{})["name"].(string), "Robot1") + assert.Equal(t, "Robot1", body["robot"].(map[string]interface{})["name"].(string)) // unknown robot request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1", nil) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Robot found with the name UnknownRobot1") + assert.Equal(t, "No Robot found with the name UnknownRobot1", body["error"]) } func TestRobotDevices(t *testing.T) { @@ -177,14 +177,14 @@ func TestRobotDevices(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, len(body["devices"].([]interface{})), 3) + assert.Equal(t, 3, len(body["devices"].([]interface{}))) // unknown robot request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1/devices", nil) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Robot found with the name UnknownRobot1") + assert.Equal(t, "No Robot found with the name UnknownRobot1", body["error"]) } func TestRobotCommands(t *testing.T) { @@ -197,14 +197,14 @@ func TestRobotCommands(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["commands"], []interface{}{"robotTestFunction"}) + assert.Equal(t, []interface{}{"robotTestFunction"}, body["commands"]) // unknown robot request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1/commands", nil) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Robot found with the name UnknownRobot1") + assert.Equal(t, "No Robot found with the name UnknownRobot1", body["error"]) } func TestExecuteRobotCommand(t *testing.T) { @@ -220,7 +220,7 @@ func TestExecuteRobotCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["result"], "hey Robot1, Beep Boop") + assert.Equal(t, "hey Robot1, Beep Boop", body.(map[string]interface{})["result"]) // unknown command request, _ = http.NewRequest("GET", @@ -232,7 +232,7 @@ func TestExecuteRobotCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["error"], "Unknown Command") + assert.Equal(t, "Unknown Command", body.(map[string]interface{})["error"]) // uknown robot request, _ = http.NewRequest("GET", @@ -243,7 +243,7 @@ func TestExecuteRobotCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["error"], "No Robot found with the name UnknownRobot1") + assert.Equal(t, "No Robot found with the name UnknownRobot1", body.(map[string]interface{})["error"]) } func TestRobotDevice(t *testing.T) { @@ -259,7 +259,7 @@ func TestRobotDevice(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["device"].(map[string]interface{})["name"].(string), "Device1") + assert.Equal(t, "Device1", body["device"].(map[string]interface{})["name"].(string)) // unknown device request, _ = http.NewRequest("GET", @@ -267,7 +267,7 @@ func TestRobotDevice(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Device found with the name UnknownDevice1") + assert.Equal(t, "No Device found with the name UnknownDevice1", body["error"]) } func TestRobotDeviceCommands(t *testing.T) { @@ -283,7 +283,7 @@ func TestRobotDeviceCommands(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, len(body["commands"].([]interface{})), 2) + assert.Equal(t, 2, len(body["commands"].([]interface{}))) // unknown device request, _ = http.NewRequest("GET", @@ -292,7 +292,7 @@ func TestRobotDeviceCommands(t *testing.T) { ) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Device found with the name UnknownDevice1") + assert.Equal(t, "No Device found with the name UnknownDevice1", body["error"]) } func TestExecuteRobotDeviceCommand(t *testing.T) { @@ -309,7 +309,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["result"].(string), "hello human") + assert.Equal(t, "hello human", body.(map[string]interface{})["result"].(string)) // unknown command request, _ = http.NewRequest("GET", @@ -321,7 +321,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["error"], "Unknown Command") + assert.Equal(t, "Unknown Command", body.(map[string]interface{})["error"]) // unknown device request, _ = http.NewRequest("GET", @@ -332,7 +332,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) { a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body.(map[string]interface{})["error"], "No Device found with the name UnknownDevice1") + assert.Equal(t, "No Device found with the name UnknownDevice1", body.(map[string]interface{})["error"]) } @@ -346,14 +346,14 @@ func TestRobotConnections(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, len(body["connections"].([]interface{})), 3) + assert.Equal(t, 3, len(body["connections"].([]interface{}))) // unknown robot request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1/connections", nil) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Robot found with the name UnknownRobot1") + assert.Equal(t, "No Robot found with the name UnknownRobot1", body["error"]) } func TestRobotConnection(t *testing.T) { @@ -369,7 +369,7 @@ func TestRobotConnection(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["connection"].(map[string]interface{})["name"].(string), "Connection1") + assert.Equal(t, "Connection1", body["connection"].(map[string]interface{})["name"].(string)) // unknown connection request, _ = http.NewRequest("GET", @@ -378,7 +378,7 @@ func TestRobotConnection(t *testing.T) { ) a.ServeHTTP(response, request) _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Connection found with the name UnknownConnection1") + assert.Equal(t, "No Connection found with the name UnknownConnection1", body["error"]) } func TestRobotDeviceEvent(t *testing.T) { @@ -412,7 +412,7 @@ func TestRobotDeviceEvent(t *testing.T) { case resp := <-respc: reader := bufio.NewReader(resp.Body) data, _ := reader.ReadString('\n') - gobottest.Assert(t, data, "data: \"event-data\"\n") + assert.Equal(t, "data: \"event-data\"\n", data) done = true case <-time.After(100 * time.Millisecond): t.Error("Not receiving data") @@ -427,7 +427,7 @@ func TestRobotDeviceEvent(t *testing.T) { var body map[string]interface{} _ = json.NewDecoder(response.Body).Decode(&body) - gobottest.Assert(t, body["error"], "No Event found with the name UnknownEvent") + assert.Equal(t, "No Event found with the name UnknownEvent", body["error"]) } func TestAPIRouter(t *testing.T) { @@ -437,35 +437,35 @@ func TestAPIRouter(t *testing.T) { request, _ := http.NewRequest("HEAD", "/test", nil) response := httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) a.Get("/test", func(res http.ResponseWriter, req *http.Request) {}) request, _ = http.NewRequest("GET", "/test", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) a.Post("/test", func(res http.ResponseWriter, req *http.Request) {}) request, _ = http.NewRequest("POST", "/test", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) a.Put("/test", func(res http.ResponseWriter, req *http.Request) {}) request, _ = http.NewRequest("PUT", "/test", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) a.Delete("/test", func(res http.ResponseWriter, req *http.Request) {}) request, _ = http.NewRequest("DELETE", "/test", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) a.Options("/test", func(res http.ResponseWriter, req *http.Request) {}) request, _ = http.NewRequest("OPTIONS", "/test", nil) response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) } diff --git a/api/basic_auth_test.go b/api/basic_auth_test.go index acf0aa3cf..f00033f0c 100644 --- a/api/basic_auth_test.go +++ b/api/basic_auth_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestBasicAuth(t *testing.T) { @@ -17,11 +17,11 @@ func TestBasicAuth(t *testing.T) { request.SetBasicAuth("admin", "password") response := httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 200) + assert.Equal(t, 200, response.Code) request, _ = http.NewRequest("GET", "/api/", nil) request.SetBasicAuth("admin", "wrongPassword") response = httptest.NewRecorder() a.ServeHTTP(response, request) - gobottest.Assert(t, response.Code, 401) + assert.Equal(t, 401, response.Code) } diff --git a/api/cors_test.go b/api/cors_test.go index 0e63674f6..cfd60eeb7 100644 --- a/api/cors_test.go +++ b/api/cors_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestCORSIsOriginAllowed(t *testing.T) { @@ -13,50 +13,50 @@ func TestCORSIsOriginAllowed(t *testing.T) { cors.generatePatterns() // When all the origins are accepted - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:8000"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:3001"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://server.com"), true) + assert.True(t, cors.isOriginAllowed("http://localhost:8000")) + assert.True(t, cors.isOriginAllowed("http://localhost:3001")) + assert.True(t, cors.isOriginAllowed("http://server.com")) // When one origin is accepted cors = &CORS{AllowOrigins: []string{"http://localhost:8000"}} cors.generatePatterns() - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:8000"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:3001"), false) - gobottest.Assert(t, cors.isOriginAllowed("http://server.com"), false) + assert.True(t, cors.isOriginAllowed("http://localhost:8000")) + assert.False(t, cors.isOriginAllowed("http://localhost:3001")) + assert.False(t, cors.isOriginAllowed("http://server.com")) // When several origins are accepted cors = &CORS{AllowOrigins: []string{"http://localhost:*", "http://server.com"}} cors.generatePatterns() - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:8000"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:3001"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://server.com"), true) + assert.True(t, cors.isOriginAllowed("http://localhost:8000")) + assert.True(t, cors.isOriginAllowed("http://localhost:3001")) + assert.True(t, cors.isOriginAllowed("http://server.com")) // When several origins are accepted within the same domain cors = &CORS{AllowOrigins: []string{"http://*.server.com"}} cors.generatePatterns() - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:8000"), false) - gobottest.Assert(t, cors.isOriginAllowed("http://localhost:3001"), false) - gobottest.Assert(t, cors.isOriginAllowed("http://foo.server.com"), true) - gobottest.Assert(t, cors.isOriginAllowed("http://api.server.com"), true) + assert.False(t, cors.isOriginAllowed("http://localhost:8000")) + assert.False(t, cors.isOriginAllowed("http://localhost:3001")) + assert.True(t, cors.isOriginAllowed("http://foo.server.com")) + assert.True(t, cors.isOriginAllowed("http://api.server.com")) } func TestCORSAllowedHeaders(t *testing.T) { cors := &CORS{AllowOrigins: []string{"*"}, AllowHeaders: []string{"Header1", "Header2"}} - gobottest.Assert(t, cors.AllowedHeaders(), "Header1,Header2") + assert.Equal(t, "Header1,Header2", cors.AllowedHeaders()) } func TestCORSAllowedMethods(t *testing.T) { cors := &CORS{AllowOrigins: []string{"*"}, AllowMethods: []string{"GET", "POST"}} - gobottest.Assert(t, cors.AllowedMethods(), "GET,POST") + assert.Equal(t, "GET,POST", cors.AllowedMethods()) cors.AllowMethods = []string{"GET", "POST", "PUT"} - gobottest.Assert(t, cors.AllowedMethods(), "GET,POST,PUT") + assert.Equal(t, "GET,POST,PUT", cors.AllowedMethods()) } func TestCORS(t *testing.T) { @@ -70,7 +70,7 @@ func TestCORS(t *testing.T) { request.Header.Set("Origin", allowedOrigin[0]) response := httptest.NewRecorder() api.ServeHTTP(response, request) - gobottest.Assert(t, response.Header()["Access-Control-Allow-Origin"], allowedOrigin) + assert.Equal(t, allowedOrigin, response.Header()["Access-Control-Allow-Origin"]) // Not accepted Origin disallowedOrigin := []string{"http://disallowed.com"} @@ -78,6 +78,6 @@ func TestCORS(t *testing.T) { request.Header.Set("Origin", disallowedOrigin[0]) response = httptest.NewRecorder() api.ServeHTTP(response, request) - gobottest.Refute(t, response.Header()["Access-Control-Allow-Origin"], disallowedOrigin) - gobottest.Refute(t, response.Header()["Access-Control-Allow-Origin"], allowedOrigin) + assert.NotEqual(t, disallowedOrigin, response.Header()["Access-Control-Allow-Origin"]) + assert.NotEqual(t, allowedOrigin, response.Header()["Access-Control-Allow-Origin"]) } diff --git a/commander_test.go b/commander_test.go index 074581c7a..e73021984 100644 --- a/commander_test.go +++ b/commander_test.go @@ -3,22 +3,18 @@ package gobot import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) -func TestCommaner(t *testing.T) { +func TestCommander(t *testing.T) { + // arrange c := NewCommander() c.AddCommand("test", func(map[string]interface{}) interface{} { return "hi" }) - if _, ok := c.Commands()["test"]; !ok { - t.Errorf("Could not add command to list of Commands") - } - - command := c.Command("test") - gobottest.Refute(t, command, nil) - - command = c.Command("booyeah") - gobottest.Assert(t, command, (func(map[string]interface{}) interface{})(nil)) + // act && assert + assert.Equal(t, 1, len(c.Commands())) + assert.NotNil(t, c.Command("test")) + assert.Nil(t, c.Command("booyeah")) } diff --git a/drivers/aio/analog_actuator_driver_test.go b/drivers/aio/analog_actuator_driver_test.go index 67c296ea8..ced579586 100644 --- a/drivers/aio/analog_actuator_driver_test.go +++ b/drivers/aio/analog_actuator_driver_test.go @@ -4,27 +4,27 @@ import ( "strings" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestAnalogActuatorDriver(t *testing.T) { a := newAioTestAdaptor() d := NewAnalogActuatorDriver(a, "47") - gobottest.Refute(t, d.Connection(), nil) - gobottest.Assert(t, d.Pin(), "47") + assert.NotNil(t, d.Connection()) + assert.Equal(t, "47", d.Pin()) err := d.RawWrite(100) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], 100) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, 100, a.written[0]) err = d.Write(247.0) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[1], 247) - gobottest.Assert(t, d.RawValue(), 247) - gobottest.Assert(t, d.Value(), 247.0) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, 247, a.written[1]) + assert.Equal(t, 247, d.RawValue()) + assert.Equal(t, 247.0, d.Value()) } func TestAnalogActuatorDriverWithScaler(t *testing.T) { @@ -34,14 +34,14 @@ func TestAnalogActuatorDriverWithScaler(t *testing.T) { d.SetScaler(func(input float64) int { return int((input + 3) / 2.5) }) err := d.Command("RawWrite")(map[string]interface{}{"val": "100"}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], 100) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, 100, a.written[0]) err = d.Command("Write")(map[string]interface{}{"val": "247.0"}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[1], 100) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, 100, a.written[1]) } func TestAnalogActuatorDriverLinearScaler(t *testing.T) { @@ -76,30 +76,30 @@ func TestAnalogActuatorDriverLinearScaler(t *testing.T) { // act err := d.Write(tt.input) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], tt.want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, tt.want, a.written[0]) }) } } func TestAnalogActuatorDriverStart(t *testing.T) { d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestAnalogActuatorDriverHalt(t *testing.T) { d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestAnalogActuatorDriverDefaultName(t *testing.T) { d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "AnalogActuator"), true) + assert.True(t, strings.HasPrefix(d.Name(), "AnalogActuator")) } func TestAnalogActuatorDriverSetName(t *testing.T) { d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1") d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/aio/analog_sensor_driver_test.go b/drivers/aio/analog_sensor_driver_test.go index 51371689c..12e94dc2f 100644 --- a/drivers/aio/analog_sensor_driver_test.go +++ b/drivers/aio/analog_sensor_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*AnalogSensorDriver)(nil) @@ -15,29 +15,29 @@ var _ gobot.Driver = (*AnalogSensorDriver)(nil) func TestAnalogSensorDriver(t *testing.T) { a := newAioTestAdaptor() d := NewAnalogSensorDriver(a, "1") - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) // default interval - gobottest.Assert(t, d.interval, 10*time.Millisecond) + assert.Equal(t, 10*time.Millisecond, d.interval) // commands a = newAioTestAdaptor() d = NewAnalogSensorDriver(a, "42", 30*time.Second) d.SetScaler(func(input int) float64 { return 2.5*float64(input) - 3 }) - gobottest.Assert(t, d.Pin(), "42") - gobottest.Assert(t, d.interval, 30*time.Second) + assert.Equal(t, "42", d.Pin()) + assert.Equal(t, 30*time.Second, d.interval) a.TestAdaptorAnalogRead(func() (val int, err error) { val = 100 return }) ret := d.Command("ReadRaw")(nil).(map[string]interface{}) - gobottest.Assert(t, ret["val"].(int), 100) - gobottest.Assert(t, ret["err"], nil) + assert.Equal(t, 100, ret["val"].(int)) + assert.Nil(t, ret["err"]) ret = d.Command("Read")(nil).(map[string]interface{}) - gobottest.Assert(t, ret["val"].(float64), 247.0) - gobottest.Assert(t, ret["err"], nil) + assert.Equal(t, 247.0, ret["val"].(float64)) + assert.Nil(t, ret["err"]) // refresh value on read a = newAioTestAdaptor() @@ -46,12 +46,12 @@ func TestAnalogSensorDriver(t *testing.T) { val = 150 return }) - gobottest.Assert(t, d.Value(), 0.0) + assert.Equal(t, 0.0, d.Value()) val, err := d.Read() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, val, 150.0) - gobottest.Assert(t, d.Value(), 150.0) - gobottest.Assert(t, d.RawValue(), 150) + assert.Nil(t, err) + assert.Equal(t, 150.0, val) + assert.Equal(t, 150.0, d.Value()) + assert.Equal(t, 150, d.RawValue()) } func TestAnalogSensorDriverWithLinearScaler(t *testing.T) { @@ -84,8 +84,8 @@ func TestAnalogSensorDriverWithLinearScaler(t *testing.T) { // act got, err := d.Read() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) }) } } @@ -98,12 +98,12 @@ func TestAnalogSensorDriverStart(t *testing.T) { // expect data to be received _ = d.Once(d.Event(Data), func(data interface{}) { - gobottest.Assert(t, data.(int), 100) + assert.Equal(t, 100, data.(int)) sem <- true }) _ = d.Once(d.Event(Value), func(data interface{}) { - gobottest.Assert(t, data.(float64), 10000.0) + assert.Equal(t, 10000.0, data.(float64)) sem <- true }) @@ -113,7 +113,7 @@ func TestAnalogSensorDriverStart(t *testing.T) { return }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case <-sem: @@ -123,7 +123,7 @@ func TestAnalogSensorDriverStart(t *testing.T) { // expect error to be received _ = d.Once(d.Event(Error), func(data interface{}) { - gobottest.Assert(t, data.(error).Error(), "read error") + assert.Equal(t, "read error", data.(error).Error()) sem <- true }) @@ -169,7 +169,7 @@ func TestAnalogSensorDriverHalt(t *testing.T) { <-d.halt close(done) }() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) select { case <-done: case <-time.After(100 * time.Millisecond): @@ -179,11 +179,11 @@ func TestAnalogSensorDriverHalt(t *testing.T) { func TestAnalogSensorDriverDefaultName(t *testing.T) { d := NewAnalogSensorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "AnalogSensor"), true) + assert.True(t, strings.HasPrefix(d.Name(), "AnalogSensor")) } func TestAnalogSensorDriverSetName(t *testing.T) { d := NewAnalogSensorDriver(newAioTestAdaptor(), "1") d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/aio/grove_drivers_test.go b/drivers/aio/grove_drivers_test.go index a5395a3ed..dd7b7b64b 100644 --- a/drivers/aio/grove_drivers_test.go +++ b/drivers/aio/grove_drivers_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) type DriverAndPinner interface { @@ -33,8 +33,8 @@ func TestDriverDefaults(t *testing.T) { } for _, driver := range drivers { - gobottest.Assert(t, driver.Connection(), testAdaptor) - gobottest.Assert(t, driver.Pin(), pin) + assert.Equal(t, testAdaptor, driver.Connection()) + assert.Equal(t, pin, driver.Pin()) } } @@ -90,11 +90,11 @@ func TestDriverPublishesError(t *testing.T) { } testAdaptor.TestAdaptorAnalogRead(returnErr) - gobottest.Assert(t, driver.Start(), nil) + assert.Nil(t, driver.Start()) // expect error _ = driver.Once(driver.Event(Error), func(data interface{}) { - gobottest.Assert(t, data.(error).Error(), "read error") + assert.Equal(t, "read error", data.(error).Error()) close(sem) }) diff --git a/drivers/aio/grove_temperature_sensor_driver_test.go b/drivers/aio/grove_temperature_sensor_driver_test.go index d47f0fec1..2fe8f75e3 100644 --- a/drivers/aio/grove_temperature_sensor_driver_test.go +++ b/drivers/aio/grove_temperature_sensor_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*GroveTemperatureSensorDriver)(nil) @@ -15,9 +15,9 @@ var _ gobot.Driver = (*GroveTemperatureSensorDriver)(nil) func TestGroveTemperatureSensorDriver(t *testing.T) { testAdaptor := newAioTestAdaptor() d := NewGroveTemperatureSensorDriver(testAdaptor, "123") - gobottest.Assert(t, d.Connection(), testAdaptor) - gobottest.Assert(t, d.Pin(), "123") - gobottest.Assert(t, d.interval, 10*time.Millisecond) + assert.Equal(t, testAdaptor, d.Connection()) + assert.Equal(t, "123", d.Pin()) + assert.Equal(t, 10*time.Millisecond, d.interval) } func TestGroveTemperatureSensorDriverScaling(t *testing.T) { @@ -47,8 +47,8 @@ func TestGroveTemperatureSensorDriverScaling(t *testing.T) { // act got, err := d.Read() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) }) } } @@ -63,10 +63,10 @@ func TestGroveTempSensorPublishesTemperatureInCelsius(t *testing.T) { return }) _ = d.Once(d.Event(Value), func(data interface{}) { - gobottest.Assert(t, fmt.Sprintf("%.2f", data.(float64)), "31.62") + assert.Equal(t, "31.62", fmt.Sprintf("%.2f", data.(float64))) sem <- true }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case <-sem: @@ -74,10 +74,10 @@ func TestGroveTempSensorPublishesTemperatureInCelsius(t *testing.T) { t.Errorf("Grove Temperature Sensor Event \"Data\" was not published") } - gobottest.Assert(t, d.Temperature(), 31.61532462352477) + assert.Equal(t, 31.61532462352477, d.Temperature()) } func TestGroveTempDriverDefaultName(t *testing.T) { d := NewGroveTemperatureSensorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "GroveTemperatureSensor"), true) + assert.True(t, strings.HasPrefix(d.Name(), "GroveTemperatureSensor")) } diff --git a/drivers/aio/temperature_sensor_driver_test.go b/drivers/aio/temperature_sensor_driver_test.go index b6012b7d3..0610364e1 100644 --- a/drivers/aio/temperature_sensor_driver_test.go +++ b/drivers/aio/temperature_sensor_driver_test.go @@ -7,15 +7,15 @@ import ( "testing" "time" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestTemperatureSensorDriver(t *testing.T) { testAdaptor := newAioTestAdaptor() d := NewTemperatureSensorDriver(testAdaptor, "123") - gobottest.Assert(t, d.Connection(), testAdaptor) - gobottest.Assert(t, d.Pin(), "123") - gobottest.Assert(t, d.interval, 10*time.Millisecond) + assert.Equal(t, testAdaptor, d.Connection()) + assert.Equal(t, "123", d.Pin()) + assert.Equal(t, 10*time.Millisecond, d.interval) } func TestTemperatureSensorDriverNtcScaling(t *testing.T) { @@ -48,8 +48,8 @@ func TestTemperatureSensorDriverNtcScaling(t *testing.T) { // act got, err := d.Read() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) }) } } @@ -83,8 +83,8 @@ func TestTemperatureSensorDriverLinearScaling(t *testing.T) { // act got, err := d.Read() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) }) } } @@ -101,10 +101,10 @@ func TestTempSensorPublishesTemperatureInCelsius(t *testing.T) { return }) _ = d.Once(d.Event(Value), func(data interface{}) { - gobottest.Assert(t, fmt.Sprintf("%.2f", data.(float64)), "31.62") + assert.Equal(t, "31.62", fmt.Sprintf("%.2f", data.(float64))) sem <- true }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case <-sem: @@ -112,7 +112,7 @@ func TestTempSensorPublishesTemperatureInCelsius(t *testing.T) { t.Errorf(" Temperature Sensor Event \"Data\" was not published") } - gobottest.Assert(t, d.Value(), 31.61532462352477) + assert.Equal(t, 31.61532462352477, d.Value()) } func TestTempSensorPublishesError(t *testing.T) { @@ -126,11 +126,11 @@ func TestTempSensorPublishesError(t *testing.T) { return }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) // expect error _ = d.Once(d.Event(Error), func(data interface{}) { - gobottest.Assert(t, data.(error).Error(), "read error") + assert.Equal(t, "read error", data.(error).Error()) sem <- true }) @@ -148,7 +148,7 @@ func TestTempSensorHalt(t *testing.T) { <-d.halt close(done) }() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) select { case <-done: case <-time.After(100 * time.Millisecond): @@ -158,13 +158,13 @@ func TestTempSensorHalt(t *testing.T) { func TestTempDriverDefaultName(t *testing.T) { d := NewTemperatureSensorDriver(newAioTestAdaptor(), "1") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "TemperatureSensor"), true) + assert.True(t, strings.HasPrefix(d.Name(), "TemperatureSensor")) } func TestTempDriverSetName(t *testing.T) { d := NewTemperatureSensorDriver(newAioTestAdaptor(), "1") d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } func TestTempDriver_initialize(t *testing.T) { @@ -208,7 +208,7 @@ func TestTempDriver_initialize(t *testing.T) { // act ntc.initialize() // assert - gobottest.Assert(t, ntc, tt.want) + assert.Equal(t, tt.want, ntc) }) } } diff --git a/drivers/common/mfrc522/mfrc522_pcd_test.go b/drivers/common/mfrc522/mfrc522_pcd_test.go index b640fe2a2..bf217a859 100644 --- a/drivers/common/mfrc522/mfrc522_pcd_test.go +++ b/drivers/common/mfrc522/mfrc522_pcd_test.go @@ -3,7 +3,7 @@ package mfrc522 import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) type busConnMock struct { @@ -49,7 +49,7 @@ func TestNewMFRC522Common(t *testing.T) { // act d := NewMFRC522Common() // assert - gobottest.Refute(t, d, nil) + assert.NotNil(t, d) } func TestInitialize(t *testing.T) { @@ -63,12 +63,12 @@ func TestInitialize(t *testing.T) { // act err := d.Initialize(c) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.connection, c) - gobottest.Assert(t, c.written[:3], wantSoftReset) - gobottest.Assert(t, c.written[3:21], wantInit) - gobottest.Assert(t, c.written[21:24], wantAntennaOn) - gobottest.Assert(t, c.written[24:], wantGain) + assert.Nil(t, err) + assert.Equal(t, c, d.connection) + assert.Equal(t, wantSoftReset, c.written[:3]) + assert.Equal(t, wantInit, c.written[3:21]) + assert.Equal(t, wantAntennaOn, c.written[21:24]) + assert.Equal(t, wantGain, c.written[24:]) } func Test_getVersion(t *testing.T) { @@ -80,9 +80,9 @@ func Test_getVersion(t *testing.T) { // act got, err := d.getVersion() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, want) - gobottest.Assert(t, c.written, wantWritten) + assert.Nil(t, err) + assert.Equal(t, want, got) + assert.Equal(t, wantWritten, c.written) } func Test_switchAntenna(t *testing.T) { @@ -120,8 +120,8 @@ func Test_switchAntenna(t *testing.T) { // act err := d.switchAntenna(tc.target) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written, tc.wantWritten) + assert.Nil(t, err) + assert.Equal(t, tc.wantWritten, c.written) }) } } @@ -134,8 +134,8 @@ func Test_stopCrypto1(t *testing.T) { // act err := d.stopCrypto1() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written, wantWritten) + assert.Nil(t, err) + assert.Equal(t, wantWritten, c.written) } func Test_communicateWithPICC(t *testing.T) { @@ -158,14 +158,14 @@ func Test_communicateWithPICC(t *testing.T) { // transceive, all 8 bits, no CRC err := d.communicateWithPICC(0x0C, dataToFifo, backData, 0x00, false) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written[:8], writtenPrepare) - gobottest.Assert(t, c.written[8:12], writtenWriteFifo) - gobottest.Assert(t, c.written[12:16], writtenTransceive) - gobottest.Assert(t, c.written[16:19], writtenBitFramingStart) - gobottest.Assert(t, c.written[19:24], writtenWaitAndFinish) - gobottest.Assert(t, c.written[24:], writtenReadFifo) - gobottest.Assert(t, backData, []byte{0x11, 0x22}) + assert.Nil(t, err) + assert.Equal(t, writtenPrepare, c.written[:8]) + assert.Equal(t, writtenWriteFifo, c.written[8:12]) + assert.Equal(t, writtenTransceive, c.written[12:16]) + assert.Equal(t, writtenBitFramingStart, c.written[16:19]) + assert.Equal(t, writtenWaitAndFinish, c.written[19:24]) + assert.Equal(t, writtenReadFifo, c.written[24:]) + assert.Equal(t, []byte{0x11, 0x22}, backData) } func Test_calculateCRC(t *testing.T) { @@ -181,12 +181,12 @@ func Test_calculateCRC(t *testing.T) { // act err := d.calculateCRC(dataToFifo, gotCrcBack) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written[:6], writtenPrepare) - gobottest.Assert(t, c.written[6:10], writtenFifo) - gobottest.Assert(t, c.written[10:15], writtenCalc) - gobottest.Assert(t, c.written[15:], writtenGetResult) - gobottest.Assert(t, gotCrcBack, []byte{0x11, 0x22}) + assert.Nil(t, err) + assert.Equal(t, writtenPrepare, c.written[:6]) + assert.Equal(t, writtenFifo, c.written[6:10]) + assert.Equal(t, writtenCalc, c.written[10:15]) + assert.Equal(t, writtenGetResult, c.written[15:]) + assert.Equal(t, []byte{0x11, 0x22}, gotCrcBack) } func Test_writeFifo(t *testing.T) { @@ -197,8 +197,8 @@ func Test_writeFifo(t *testing.T) { // act err := d.writeFifo(dataToFifo) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written, wantWritten) + assert.Nil(t, err) + assert.Equal(t, wantWritten, c.written) } func Test_readFifo(t *testing.T) { @@ -210,7 +210,7 @@ func Test_readFifo(t *testing.T) { // act _, err := d.readFifo(backData) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, c.written, wantWritten) - gobottest.Assert(t, backData, c.simFifo) + assert.Nil(t, err) + assert.Equal(t, wantWritten, c.written) + assert.Equal(t, c.simFifo, backData) } diff --git a/drivers/gpio/aip1640_driver_test.go b/drivers/gpio/aip1640_driver_test.go index 796ba8b46..2b63ac39c 100644 --- a/drivers/gpio/aip1640_driver_test.go +++ b/drivers/gpio/aip1640_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*AIP1640Driver)(nil) @@ -32,62 +32,62 @@ func TestAIP1640Driver(t *testing.T) { func TestAIP1640DriverStart(t *testing.T) { d := initTestAIP1640Driver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestAIP1640DriverHalt(t *testing.T) { d := initTestAIP1640Driver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestAIP1640DriverDefaultName(t *testing.T) { d := initTestAIP1640Driver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "AIP1640Driver"), true) + assert.True(t, strings.HasPrefix(d.Name(), "AIP1640Driver")) } func TestAIP1640DriverSetName(t *testing.T) { d := initTestAIP1640Driver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } func TestAIP1640DriveDrawPixel(t *testing.T) { d := initTestAIP1640Driver() d.DrawPixel(2, 3, true) d.DrawPixel(0, 3, true) - gobottest.Assert(t, uint8(5), d.buffer[7-3]) + assert.Equal(t, d.buffer[7-3], uint8(5)) } func TestAIP1640DriverDrawRow(t *testing.T) { d := initTestAIP1640Driver() d.DrawRow(4, 0x3C) - gobottest.Assert(t, uint8(0x3C), d.buffer[7-4]) + assert.Equal(t, d.buffer[7-4], uint8(0x3C)) } func TestAIP1640DriverDrawMatrix(t *testing.T) { d := initTestAIP1640Driver() drawing := [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} d.DrawMatrix(drawing) - gobottest.Assert(t, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, d.buffer) + assert.Equal(t, d.buffer, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}) } func TestAIP1640DriverClear(t *testing.T) { d := initTestAIP1640Driver() drawing := [8]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} d.DrawMatrix(drawing) - gobottest.Assert(t, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, d.buffer) + assert.Equal(t, d.buffer, [8]byte{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}) d.Clear() - gobottest.Assert(t, [8]byte{}, d.buffer) + assert.Equal(t, d.buffer, [8]byte{}) } func TestAIP1640DriverSetIntensity(t *testing.T) { d := initTestAIP1640Driver() d.SetIntensity(3) - gobottest.Assert(t, uint8(3), d.intensity) + assert.Equal(t, d.intensity, uint8(3)) } func TestAIP1640DriverSetIntensityHigherThan7(t *testing.T) { d := initTestAIP1640Driver() d.SetIntensity(19) - gobottest.Assert(t, uint8(7), d.intensity) + assert.Equal(t, d.intensity, uint8(7)) } diff --git a/drivers/gpio/button_driver_test.go b/drivers/gpio/button_driver_test.go index aa458c88c..7910bc7bc 100644 --- a/drivers/gpio/button_driver_test.go +++ b/drivers/gpio/button_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*ButtonDriver)(nil) @@ -23,15 +23,15 @@ func TestButtonDriverHalt(t *testing.T) { go func() { <-d.halt }() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestButtonDriver(t *testing.T) { d := NewButtonDriver(newGpioTestAdaptor(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) d = NewButtonDriver(newGpioTestAdaptor(), "1", 30*time.Second) - gobottest.Assert(t, d.interval, 30*time.Second) + assert.Equal(t, 30*time.Second, d.interval) } func TestButtonDriverStart(t *testing.T) { @@ -40,7 +40,7 @@ func TestButtonDriverStart(t *testing.T) { d := NewButtonDriver(a, "1") _ = d.Once(ButtonPush, func(data interface{}) { - gobottest.Assert(t, d.Active, true) + assert.True(t, d.Active) sem <- true }) @@ -49,7 +49,7 @@ func TestButtonDriverStart(t *testing.T) { return }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case <-sem: @@ -58,7 +58,7 @@ func TestButtonDriverStart(t *testing.T) { } _ = d.Once(ButtonRelease, func(data interface{}) { - gobottest.Assert(t, d.Active, false) + assert.False(t, d.Active) sem <- true }) @@ -113,7 +113,7 @@ func TestButtonDriverDefaultState(t *testing.T) { d.DefaultState = 1 _ = d.Once(ButtonPush, func(data interface{}) { - gobottest.Assert(t, d.Active, true) + assert.True(t, d.Active) sem <- true }) @@ -122,7 +122,7 @@ func TestButtonDriverDefaultState(t *testing.T) { return }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case <-sem: @@ -131,7 +131,7 @@ func TestButtonDriverDefaultState(t *testing.T) { } _ = d.Once(ButtonRelease, func(data interface{}) { - gobottest.Assert(t, d.Active, false) + assert.False(t, d.Active) sem <- true }) @@ -149,11 +149,11 @@ func TestButtonDriverDefaultState(t *testing.T) { func TestButtonDriverDefaultName(t *testing.T) { g := initTestButtonDriver() - gobottest.Assert(t, strings.HasPrefix(g.Name(), "Button"), true) + assert.True(t, strings.HasPrefix(g.Name(), "Button")) } func TestButtonDriverSetName(t *testing.T) { g := initTestButtonDriver() g.SetName("mybot") - gobottest.Assert(t, g.Name(), "mybot") + assert.Equal(t, "mybot", g.Name()) } diff --git a/drivers/gpio/buzzer_driver_test.go b/drivers/gpio/buzzer_driver_test.go index 3edb43ea5..94af0cc8f 100644 --- a/drivers/gpio/buzzer_driver_test.go +++ b/drivers/gpio/buzzer_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*BuzzerDriver)(nil) @@ -17,37 +17,37 @@ func initTestBuzzerDriver(conn DigitalWriter) *BuzzerDriver { func TestBuzzerDriverDefaultName(t *testing.T) { g := initTestBuzzerDriver(newGpioTestAdaptor()) - gobottest.Assert(t, strings.HasPrefix(g.Name(), "Buzzer"), true) + assert.True(t, strings.HasPrefix(g.Name(), "Buzzer")) } func TestBuzzerDriverSetName(t *testing.T) { g := initTestBuzzerDriver(newGpioTestAdaptor()) g.SetName("mybot") - gobottest.Assert(t, g.Name(), "mybot") + assert.Equal(t, "mybot", g.Name()) } func TestBuzzerDriverStart(t *testing.T) { d := initTestBuzzerDriver(newGpioTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestBuzzerDriverHalt(t *testing.T) { d := initTestBuzzerDriver(newGpioTestAdaptor()) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestBuzzerDriverToggle(t *testing.T) { d := initTestBuzzerDriver(newGpioTestAdaptor()) _ = d.Off() _ = d.Toggle() - gobottest.Assert(t, d.State(), true) + assert.True(t, d.State()) _ = d.Toggle() - gobottest.Assert(t, d.State(), false) + assert.False(t, d.State()) } func TestBuzzerDriverTone(t *testing.T) { d := initTestBuzzerDriver(newGpioTestAdaptor()) - gobottest.Assert(t, d.Tone(100, 0.01), nil) + assert.Nil(t, d.Tone(100, 0.01)) } func TestBuzzerDriverOnError(t *testing.T) { @@ -57,7 +57,8 @@ func TestBuzzerDriverOnError(t *testing.T) { return errors.New("write error") }) - gobottest.Assert(t, d.On(), errors.New("write error")) + //assert.Errorf(t, d.On(), "write error") + assert.Errorf(t, d.On(), "write error") } func TestBuzzerDriverOffError(t *testing.T) { @@ -67,7 +68,7 @@ func TestBuzzerDriverOffError(t *testing.T) { return errors.New("write error") }) - gobottest.Assert(t, d.Off(), errors.New("write error")) + assert.Errorf(t, d.Off(), "write error") } func TestBuzzerDriverToneError(t *testing.T) { @@ -77,5 +78,5 @@ func TestBuzzerDriverToneError(t *testing.T) { return errors.New("write error") }) - gobottest.Assert(t, d.Tone(100, 0.01), errors.New("write error")) + assert.Errorf(t, d.Tone(100, 0.01), "write error") } diff --git a/drivers/gpio/direct_pin_driver_test.go b/drivers/gpio/direct_pin_driver_test.go index 2a0815a4e..1c8faaca1 100644 --- a/drivers/gpio/direct_pin_driver_test.go +++ b/drivers/gpio/direct_pin_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*DirectPinDriver)(nil) @@ -34,138 +34,138 @@ func TestDirectPinDriver(t *testing.T) { var err interface{} d := initTestDirectPinDriver() - gobottest.Assert(t, d.Pin(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.Equal(t, "1", d.Pin()) + assert.NotNil(t, d.Connection()) ret = d.Command("DigitalRead")(nil).(map[string]interface{}) - gobottest.Assert(t, ret["val"].(int), 1) - gobottest.Assert(t, ret["err"], nil) + assert.Equal(t, 1, ret["val"].(int)) + assert.Nil(t, ret["err"]) err = d.Command("DigitalWrite")(map[string]interface{}{"level": "1"}) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") err = d.Command("PwmWrite")(map[string]interface{}{"level": "1"}) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") err = d.Command("ServoWrite")(map[string]interface{}{"level": "1"}) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") } func TestDirectPinDriverStart(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestDirectPinDriverHalt(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestDirectPinDriverOff(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Refute(t, d.Off(), nil) + assert.NotNil(t, d.Off()) a := newGpioTestAdaptor() d = NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.Off(), nil) + assert.Nil(t, d.Off()) } func TestDirectPinDriverOffNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.Off(), errors.New("DigitalWrite is not supported by this platform")) + assert.Errorf(t, d.Off(), "DigitalWrite is not supported by this platform") } func TestDirectPinDriverOn(t *testing.T) { a := newGpioTestAdaptor() d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.On(), nil) + assert.Nil(t, d.On()) } func TestDirectPinDriverOnError(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Refute(t, d.On(), nil) + assert.NotNil(t, d.On()) } func TestDirectPinDriverOnNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.On(), errors.New("DigitalWrite is not supported by this platform")) + assert.Errorf(t, d.On(), "DigitalWrite is not supported by this platform") } func TestDirectPinDriverDigitalWrite(t *testing.T) { adaptor := newGpioTestAdaptor() d := NewDirectPinDriver(adaptor, "1") - gobottest.Assert(t, d.DigitalWrite(1), nil) + assert.Nil(t, d.DigitalWrite(1)) } func TestDirectPinDriverDigitalWriteNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.DigitalWrite(1), errors.New("DigitalWrite is not supported by this platform")) + assert.Errorf(t, d.DigitalWrite(1), "DigitalWrite is not supported by this platform") } func TestDirectPinDriverDigitalWriteError(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Refute(t, d.DigitalWrite(1), nil) + assert.NotNil(t, d.DigitalWrite(1)) } func TestDirectPinDriverDigitalRead(t *testing.T) { d := initTestDirectPinDriver() ret, err := d.DigitalRead() - gobottest.Assert(t, ret, 1) - gobottest.Assert(t, err, nil) + assert.Equal(t, 1, ret) + assert.Nil(t, err) } func TestDirectPinDriverDigitalReadNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") _, e := d.DigitalRead() - gobottest.Assert(t, e, errors.New("DigitalRead is not supported by this platform")) + assert.Errorf(t, e, "DigitalRead is not supported by this platform") } func TestDirectPinDriverPwmWrite(t *testing.T) { a := newGpioTestAdaptor() d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.PwmWrite(1), nil) + assert.Nil(t, d.PwmWrite(1)) } func TestDirectPinDriverPwmWriteNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.PwmWrite(1), errors.New("PwmWrite is not supported by this platform")) + assert.Errorf(t, d.PwmWrite(1), "PwmWrite is not supported by this platform") } func TestDirectPinDriverPwmWriteError(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Refute(t, d.PwmWrite(1), nil) + assert.NotNil(t, d.PwmWrite(1)) } func TestDirectPinDriverServoWrite(t *testing.T) { a := newGpioTestAdaptor() d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.ServoWrite(1), nil) + assert.Nil(t, d.ServoWrite(1)) } func TestDirectPinDriverServoWriteNotSupported(t *testing.T) { a := &gpioTestBareAdaptor{} d := NewDirectPinDriver(a, "1") - gobottest.Assert(t, d.ServoWrite(1), errors.New("ServoWrite is not supported by this platform")) + assert.Errorf(t, d.ServoWrite(1), "ServoWrite is not supported by this platform") } func TestDirectPinDriverServoWriteError(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Refute(t, d.ServoWrite(1), nil) + assert.NotNil(t, d.ServoWrite(1)) } func TestDirectPinDriverDefaultName(t *testing.T) { d := initTestDirectPinDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Direct"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Direct")) } func TestDirectPinDriverSetName(t *testing.T) { d := initTestDirectPinDriver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/easy_driver_test.go b/drivers/gpio/easy_driver_test.go index baaf69170..669aeeb7b 100644 --- a/drivers/gpio/easy_driver_test.go +++ b/drivers/gpio/easy_driver_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) const ( @@ -22,18 +22,18 @@ func initEasyDriver() *EasyDriver { func TestEasyDriver_Connection(t *testing.T) { d := initEasyDriver() - gobottest.Assert(t, d.Connection(), adapter) + assert.Equal(t, adapter, d.Connection()) } func TestEasyDriverDefaultName(t *testing.T) { d := initEasyDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "EasyDriver"), true) + assert.True(t, strings.HasPrefix(d.Name(), "EasyDriver")) } func TestEasyDriverSetName(t *testing.T) { d := initEasyDriver() d.SetName("OtherDriver") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "OtherDriver"), true) + assert.True(t, strings.HasPrefix(d.Name(), "OtherDriver")) } func TestEasyDriverStart(t *testing.T) { @@ -45,142 +45,142 @@ func TestEasyDriverStart(t *testing.T) { func TestEasyDriverHalt(t *testing.T) { d := initEasyDriver() _ = d.Run() - gobottest.Assert(t, d.IsMoving(), true) + assert.True(t, d.IsMoving()) _ = d.Halt() - gobottest.Assert(t, d.IsMoving(), false) + assert.False(t, d.IsMoving()) } func TestEasyDriverMove(t *testing.T) { d := initEasyDriver() _ = d.Move(2) time.Sleep(2 * time.Millisecond) - gobottest.Assert(t, d.GetCurrentStep(), 4) - gobottest.Assert(t, d.IsMoving(), false) + assert.Equal(t, 4, d.GetCurrentStep()) + assert.False(t, d.IsMoving()) } func TestEasyDriverRun(t *testing.T) { d := initEasyDriver() _ = d.Run() - gobottest.Assert(t, d.IsMoving(), true) + assert.True(t, d.IsMoving()) _ = d.Run() - gobottest.Assert(t, d.IsMoving(), true) + assert.True(t, d.IsMoving()) } func TestEasyDriverStop(t *testing.T) { d := initEasyDriver() _ = d.Run() - gobottest.Assert(t, d.IsMoving(), true) + assert.True(t, d.IsMoving()) _ = d.Stop() - gobottest.Assert(t, d.IsMoving(), false) + assert.False(t, d.IsMoving()) } func TestEasyDriverStep(t *testing.T) { d := initEasyDriver() _ = d.Step() - gobottest.Assert(t, d.GetCurrentStep(), 1) + assert.Equal(t, 1, d.GetCurrentStep()) _ = d.Step() _ = d.Step() _ = d.Step() - gobottest.Assert(t, d.GetCurrentStep(), 4) + assert.Equal(t, 4, d.GetCurrentStep()) _ = d.SetDirection("ccw") _ = d.Step() - gobottest.Assert(t, d.GetCurrentStep(), 3) + assert.Equal(t, 3, d.GetCurrentStep()) } func TestEasyDriverSetDirection(t *testing.T) { d := initEasyDriver() - gobottest.Assert(t, d.dir, int8(1)) + assert.Equal(t, int8(1), d.dir) _ = d.SetDirection("cw") - gobottest.Assert(t, d.dir, int8(1)) + assert.Equal(t, int8(1), d.dir) _ = d.SetDirection("ccw") - gobottest.Assert(t, d.dir, int8(-1)) + assert.Equal(t, int8(-1), d.dir) _ = d.SetDirection("nothing") - gobottest.Assert(t, d.dir, int8(1)) + assert.Equal(t, int8(1), d.dir) } func TestEasyDriverSetDirectionNoPin(t *testing.T) { d := initEasyDriver() d.dirPin = "" err := d.SetDirection("cw") - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) } func TestEasyDriverSetSpeed(t *testing.T) { d := initEasyDriver() - gobottest.Assert(t, d.rpm, uint(stepsPerRev/4)) // default speed of 720/4 + assert.Equal(t, uint(stepsPerRev/4), d.rpm) // default speed of 720/4 _ = d.SetSpeed(0) - gobottest.Assert(t, d.rpm, uint(1)) + assert.Equal(t, uint(1), d.rpm) _ = d.SetSpeed(200) - gobottest.Assert(t, d.rpm, uint(200)) + assert.Equal(t, uint(200), d.rpm) _ = d.SetSpeed(1000) - gobottest.Assert(t, d.rpm, uint(stepsPerRev)) + assert.Equal(t, uint(stepsPerRev), d.rpm) } func TestEasyDriverGetMaxSpeed(t *testing.T) { d := initEasyDriver() - gobottest.Assert(t, d.GetMaxSpeed(), uint(stepsPerRev)) + assert.Equal(t, uint(stepsPerRev), d.GetMaxSpeed()) } func TestEasyDriverSleep(t *testing.T) { // let's test basic functionality d := initEasyDriver() _ = d.Sleep() - gobottest.Assert(t, d.IsSleeping(), true) + assert.True(t, d.IsSleeping()) // let's make sure it stops first d = initEasyDriver() _ = d.Run() _ = d.Sleep() - gobottest.Assert(t, d.IsSleeping(), true) - gobottest.Assert(t, d.IsMoving(), false) + assert.True(t, d.IsSleeping()) + assert.False(t, d.IsMoving()) } func TestEasyDriverSleepNoPin(t *testing.T) { d := initEasyDriver() d.sleepPin = "" err := d.Sleep() - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) err = d.Wake() - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) } func TestEasyDriverWake(t *testing.T) { // let's test basic functionality d := initEasyDriver() _ = d.Sleep() - gobottest.Assert(t, d.IsSleeping(), true) + assert.True(t, d.IsSleeping()) _ = d.Wake() - gobottest.Assert(t, d.IsSleeping(), false) + assert.False(t, d.IsSleeping()) } func TestEasyDriverEnable(t *testing.T) { // let's test basic functionality d := initEasyDriver() _ = d.Disable() - gobottest.Assert(t, d.IsEnabled(), false) + assert.False(t, d.IsEnabled()) _ = d.Enable() - gobottest.Assert(t, d.IsEnabled(), true) + assert.True(t, d.IsEnabled()) } func TestEasyDriverEnableNoPin(t *testing.T) { d := initEasyDriver() d.enPin = "" err := d.Disable() - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) err = d.Enable() - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) } func TestEasyDriverDisable(t *testing.T) { // let's test basic functionality d := initEasyDriver() _ = d.Disable() - gobottest.Assert(t, d.IsEnabled(), false) + assert.False(t, d.IsEnabled()) // let's make sure it stops first d = initEasyDriver() _ = d.Run() _ = d.Disable() - gobottest.Assert(t, d.IsEnabled(), false) - gobottest.Assert(t, d.IsMoving(), false) + assert.False(t, d.IsEnabled()) + assert.False(t, d.IsMoving()) } diff --git a/drivers/gpio/grove_drivers_test.go b/drivers/gpio/grove_drivers_test.go index 35f3ac840..d201a41a3 100644 --- a/drivers/gpio/grove_drivers_test.go +++ b/drivers/gpio/grove_drivers_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) type DriverAndPinner interface { @@ -35,8 +35,8 @@ func TestDriverDefaults(t *testing.T) { } for _, driver := range drivers { - gobottest.Assert(t, driver.Connection(), testAdaptor) - gobottest.Assert(t, driver.Pin(), pin) + assert.Equal(t, testAdaptor, driver.Connection()) + assert.Equal(t, pin, driver.Pin()) } } @@ -91,11 +91,11 @@ func TestDriverPublishesError(t *testing.T) { } testAdaptor.testAdaptorDigitalRead = returnErr - gobottest.Assert(t, driver.Start(), nil) + assert.Nil(t, driver.Start()) // expect error _ = driver.Once(driver.Event(Error), func(data interface{}) { - gobottest.Assert(t, data.(error).Error(), "read error") + assert.Equal(t, "read error", data.(error).Error()) close(sem) }) diff --git a/drivers/gpio/hd44780_driver_test.go b/drivers/gpio/hd44780_driver_test.go index 5a4ccadb7..dc4c01e16 100644 --- a/drivers/gpio/hd44780_driver_test.go +++ b/drivers/gpio/hd44780_driver_test.go @@ -5,8 +5,9 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" + "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*HD44780Driver)(nil) @@ -60,23 +61,23 @@ func TestHD44780Driver(t *testing.T) { func TestHD44780DriverHalt(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestHD44780DriverDefaultName(t *testing.T) { d, _ := initTestHD44780Driver4BitModeWithStubbedAdaptor() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "HD44780Driver"), true) + assert.True(t, strings.HasPrefix(d.Name(), "HD44780Driver")) } func TestHD44780DriverSetName(t *testing.T) { d, _ := initTestHD44780Driver4BitModeWithStubbedAdaptor() d.SetName("my driver") - gobottest.Assert(t, d.Name(), "my driver") + assert.Equal(t, "my driver", d.Name()) } func TestHD44780DriverStart(t *testing.T) { d, _ := initTestHD44780Driver4BitModeWithStubbedAdaptor() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestHD44780DriverStartError(t *testing.T) { @@ -92,7 +93,7 @@ func TestHD44780DriverStartError(t *testing.T) { D7: "", } d = NewHD44780Driver(a, 2, 16, HD44780_4BITMODE, "13", "15", pins) - gobottest.Assert(t, d.Start(), errors.New("Initialization error")) + assert.Errorf(t, d.Start(), "Initialization error") pins = HD44780DataPin{ D0: "31", @@ -105,7 +106,7 @@ func TestHD44780DriverStartError(t *testing.T) { D7: "", } d = NewHD44780Driver(a, 2, 16, HD44780_8BITMODE, "13", "15", pins) - gobottest.Assert(t, d.Start(), errors.New("Initialization error")) + assert.Errorf(t, d.Start(), "Initialization error") } func TestHD44780DriverWrite(t *testing.T) { @@ -113,11 +114,11 @@ func TestHD44780DriverWrite(t *testing.T) { d, _ = initTestHD44780Driver4BitModeWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Write("hello gobot"), nil) + assert.Nil(t, d.Write("hello gobot")) d, _ = initTestHD44780Driver8BitModeWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Write("hello gobot"), nil) + assert.Nil(t, d.Write("hello gobot")) } func TestHD44780DriverWriteError(t *testing.T) { @@ -129,107 +130,108 @@ func TestHD44780DriverWriteError(t *testing.T) { return errors.New("write error") } _ = d.Start() - gobottest.Assert(t, d.Write("hello gobot"), errors.New("write error")) + assert.Errorf(t, d.Write("hello gobot"), "write error") d, a = initTestHD44780Driver8BitModeWithStubbedAdaptor() a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") } _ = d.Start() - gobottest.Assert(t, d.Write("hello gobot"), errors.New("write error")) + assert.Errorf(t, d.Write("hello gobot"), "write error") } func TestHD44780DriverClear(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Clear(), nil) + assert.Nil(t, d.Clear()) } func TestHD44780DriverHome(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Home(), nil) + assert.Nil(t, d.Home()) } func TestHD44780DriverSetCursor(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.SetCursor(0, 3), nil) + assert.Nil(t, d.SetCursor(0, 3)) } func TestHD44780DriverSetCursorInvalid(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.SetCursor(-1, 3), errors.New("Invalid position value (-1, 3), range (1, 15)")) - gobottest.Assert(t, d.SetCursor(2, 3), errors.New("Invalid position value (2, 3), range (1, 15)")) - gobottest.Assert(t, d.SetCursor(0, -1), errors.New("Invalid position value (0, -1), range (1, 15)")) - gobottest.Assert(t, d.SetCursor(0, 16), errors.New("Invalid position value (0, 16), range (1, 15)")) + + assert.Errorf(t, d.SetCursor(-1, 3), "Invalid position value (-1, 3), range (1, 15)") + assert.Errorf(t, d.SetCursor(2, 3), "Invalid position value (2, 3), range (1, 15)") + assert.Errorf(t, d.SetCursor(0, -1), "Invalid position value (0, -1), range (1, 15)") + assert.Errorf(t, d.SetCursor(0, 16), "Invalid position value (0, 16), range (1, 15)") } func TestHD44780DriverDisplayOn(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Display(true), nil) + assert.Nil(t, d.Display(true)) } func TestHD44780DriverDisplayOff(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Display(false), nil) + assert.Nil(t, d.Display(false)) } func TestHD44780DriverCursorOn(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Cursor(true), nil) + assert.Nil(t, d.Cursor(true)) } func TestHD44780DriverCursorOff(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Cursor(false), nil) + assert.Nil(t, d.Cursor(false)) } func TestHD44780DriverBlinkOn(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Blink(true), nil) + assert.Nil(t, d.Blink(true)) } func TestHD44780DriverBlinkOff(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.Blink(false), nil) + assert.Nil(t, d.Blink(false)) } func TestHD44780DriverScrollLeft(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.ScrollLeft(), nil) + assert.Nil(t, d.ScrollLeft()) } func TestHD44780DriverScrollRight(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.ScrollRight(), nil) + assert.Nil(t, d.ScrollRight()) } func TestHD44780DriverLeftToRight(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.LeftToRight(), nil) + assert.Nil(t, d.LeftToRight()) } func TestHD44780DriverRightToLeft(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.RightToLeft(), nil) + assert.Nil(t, d.RightToLeft()) } func TestHD44780DriverSendCommand(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.SendCommand(0x33), nil) + assert.Nil(t, d.SendCommand(0x33)) } func TestHD44780DriverWriteChar(t *testing.T) { d := initTestHD44780Driver() - gobottest.Assert(t, d.WriteChar(0x41), nil) + assert.Nil(t, d.WriteChar(0x41)) } func TestHD44780DriverCreateChar(t *testing.T) { d := initTestHD44780Driver() charMap := [8]byte{1, 2, 3, 4, 5, 6, 7, 8} - gobottest.Assert(t, d.CreateChar(0, charMap), nil) + assert.Nil(t, d.CreateChar(0, charMap)) } func TestHD44780DriverCreateCharError(t *testing.T) { d := initTestHD44780Driver() charMap := [8]byte{1, 2, 3, 4, 5, 6, 7, 8} - gobottest.Assert(t, d.CreateChar(8, charMap), errors.New("can't set a custom character at a position greater than 7")) + assert.Errorf(t, d.CreateChar(8, charMap), "can't set a custom character at a position greater than 7") } diff --git a/drivers/gpio/led_driver_test.go b/drivers/gpio/led_driver_test.go index cd6fc57f0..9e02e5a9b 100644 --- a/drivers/gpio/led_driver_test.go +++ b/drivers/gpio/led_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*LedDriver)(nil) @@ -27,8 +27,8 @@ func TestLedDriver(t *testing.T) { a := newGpioTestAdaptor() d := NewLedDriver(a, "1") - gobottest.Assert(t, d.Pin(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.Equal(t, "1", d.Pin()) + assert.NotNil(t, d.Connection()) a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") @@ -38,36 +38,36 @@ func TestLedDriver(t *testing.T) { } err = d.Command("Toggle")(nil) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") err = d.Command("On")(nil) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") err = d.Command("Off")(nil) - gobottest.Assert(t, err.(error), errors.New("write error")) + assert.Errorf(t, err.(error), "write error") err = d.Command("Brightness")(map[string]interface{}{"level": 100.0}) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") } func TestLedDriverStart(t *testing.T) { d := initTestLedDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestLedDriverHalt(t *testing.T) { d := initTestLedDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestLedDriverToggle(t *testing.T) { d := initTestLedDriver() _ = d.Off() _ = d.Toggle() - gobottest.Assert(t, d.State(), true) + assert.True(t, d.State()) _ = d.Toggle() - gobottest.Assert(t, d.State(), false) + assert.False(t, d.State()) } func TestLedDriverBrightness(t *testing.T) { @@ -77,18 +77,18 @@ func TestLedDriverBrightness(t *testing.T) { err = errors.New("pwm error") return } - gobottest.Assert(t, d.Brightness(150), errors.New("pwm error")) + assert.Errorf(t, d.Brightness(150), "pwm error") } func TestLEDDriverDefaultName(t *testing.T) { a := newGpioTestAdaptor() d := NewLedDriver(a, "1") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "LED"), true) + assert.True(t, strings.HasPrefix(d.Name(), "LED")) } func TestLEDDriverSetName(t *testing.T) { a := newGpioTestAdaptor() d := NewLedDriver(a, "1") d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/makey_button_driver_test.go b/drivers/gpio/makey_button_driver_test.go index 0fb54c144..c810f767b 100644 --- a/drivers/gpio/makey_button_driver_test.go +++ b/drivers/gpio/makey_button_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*MakeyButtonDriver)(nil) @@ -24,7 +24,7 @@ func TestMakeyButtonDriverHalt(t *testing.T) { <-d.halt close(done) }() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) select { case <-done: case <-time.After(makeyTestDelay * time.Millisecond): @@ -34,12 +34,12 @@ func TestMakeyButtonDriverHalt(t *testing.T) { func TestMakeyButtonDriver(t *testing.T) { d := initTestMakeyButtonDriver() - gobottest.Assert(t, d.Pin(), "1") - gobottest.Refute(t, d.Connection(), nil) - gobottest.Assert(t, d.interval, 10*time.Millisecond) + assert.Equal(t, "1", d.Pin()) + assert.NotNil(t, d.Connection()) + assert.Equal(t, 10*time.Millisecond, d.interval) d = NewMakeyButtonDriver(newGpioTestAdaptor(), "1", 30*time.Second) - gobottest.Assert(t, d.interval, 30*time.Second) + assert.Equal(t, 30*time.Second, d.interval) } func TestMakeyButtonDriverStart(t *testing.T) { @@ -47,10 +47,10 @@ func TestMakeyButtonDriverStart(t *testing.T) { a := newGpioTestAdaptor() d := NewMakeyButtonDriver(a, "1") - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) _ = d.Once(ButtonPush, func(data interface{}) { - gobottest.Assert(t, d.Active, true) + assert.True(t, d.Active) sem <- true }) @@ -66,7 +66,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { } _ = d.Once(ButtonRelease, func(data interface{}) { - gobottest.Assert(t, d.Active, false) + assert.False(t, d.Active) sem <- true }) @@ -82,7 +82,7 @@ func TestMakeyButtonDriverStart(t *testing.T) { } _ = d.Once(Error, func(data interface{}) { - gobottest.Assert(t, data.(error).Error(), "digital read error") + assert.Equal(t, "digital read error", data.(error).Error()) sem <- true }) diff --git a/drivers/gpio/max7219_driver_test.go b/drivers/gpio/max7219_driver_test.go index dda37438b..22e92efbb 100644 --- a/drivers/gpio/max7219_driver_test.go +++ b/drivers/gpio/max7219_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*MAX7219Driver)(nil) @@ -32,21 +32,21 @@ func TestMAX7219Driver(t *testing.T) { func TestMAX7219DriverStart(t *testing.T) { d := initTestMAX7219Driver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestMAX7219DriverHalt(t *testing.T) { d := initTestMAX7219Driver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestMAX7219DriverDefaultName(t *testing.T) { d := initTestMAX7219Driver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MAX7219Driver"), true) + assert.True(t, strings.HasPrefix(d.Name(), "MAX7219Driver")) } func TestMAX7219DriverSetName(t *testing.T) { d := initTestMAX7219Driver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/motor_driver_test.go b/drivers/gpio/motor_driver_test.go index aa382fec3..b81ad5742 100644 --- a/drivers/gpio/motor_driver_test.go +++ b/drivers/gpio/motor_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*MotorDriver)(nil) @@ -16,64 +16,64 @@ func initTestMotorDriver() *MotorDriver { func TestMotorDriver(t *testing.T) { d := NewMotorDriver(newGpioTestAdaptor(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) } func TestMotorDriverStart(t *testing.T) { d := initTestMotorDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestMotorDriverHalt(t *testing.T) { d := initTestMotorDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestMotorDriverIsOn(t *testing.T) { d := initTestMotorDriver() d.CurrentMode = "digital" d.CurrentState = 1 - gobottest.Assert(t, d.IsOn(), true) + assert.True(t, d.IsOn()) d.CurrentMode = "analog" d.CurrentSpeed = 100 - gobottest.Assert(t, d.IsOn(), true) + assert.True(t, d.IsOn()) } func TestMotorDriverIsOff(t *testing.T) { d := initTestMotorDriver() _ = d.Off() - gobottest.Assert(t, d.IsOff(), true) + assert.True(t, d.IsOff()) } func TestMotorDriverOn(t *testing.T) { d := initTestMotorDriver() d.CurrentMode = "digital" _ = d.On() - gobottest.Assert(t, d.CurrentState, uint8(1)) + assert.Equal(t, uint8(1), d.CurrentState) d.CurrentMode = "analog" d.CurrentSpeed = 0 _ = d.On() - gobottest.Assert(t, d.CurrentSpeed, uint8(255)) + assert.Equal(t, uint8(255), d.CurrentSpeed) } func TestMotorDriverOff(t *testing.T) { d := initTestMotorDriver() d.CurrentMode = "digital" _ = d.Off() - gobottest.Assert(t, d.CurrentState, uint8(0)) + assert.Equal(t, uint8(0), d.CurrentState) d.CurrentMode = "analog" d.CurrentSpeed = 100 _ = d.Off() - gobottest.Assert(t, d.CurrentSpeed, uint8(0)) + assert.Equal(t, uint8(0), d.CurrentSpeed) } func TestMotorDriverToggle(t *testing.T) { d := initTestMotorDriver() _ = d.Off() _ = d.Toggle() - gobottest.Assert(t, d.IsOn(), true) + assert.True(t, d.IsOn()) _ = d.Toggle() - gobottest.Assert(t, d.IsOn(), false) + assert.False(t, d.IsOn()) } func TestMotorDriverMin(t *testing.T) { @@ -94,15 +94,15 @@ func TestMotorDriverSpeed(t *testing.T) { func TestMotorDriverForward(t *testing.T) { d := initTestMotorDriver() _ = d.Forward(100) - gobottest.Assert(t, d.CurrentSpeed, uint8(100)) - gobottest.Assert(t, d.CurrentDirection, "forward") + assert.Equal(t, uint8(100), d.CurrentSpeed) + assert.Equal(t, "forward", d.CurrentDirection) } func TestMotorDriverBackward(t *testing.T) { d := initTestMotorDriver() _ = d.Backward(100) - gobottest.Assert(t, d.CurrentSpeed, uint8(100)) - gobottest.Assert(t, d.CurrentDirection, "backward") + assert.Equal(t, uint8(100), d.CurrentSpeed) + assert.Equal(t, "backward", d.CurrentDirection) } func TestMotorDriverDirection(t *testing.T) { @@ -121,18 +121,18 @@ func TestMotorDriverDigital(t *testing.T) { d.BackwardPin = "3" _ = d.On() - gobottest.Assert(t, d.CurrentState, uint8(1)) + assert.Equal(t, uint8(1), d.CurrentState) _ = d.Off() - gobottest.Assert(t, d.CurrentState, uint8(0)) + assert.Equal(t, uint8(0), d.CurrentState) } func TestMotorDriverDefaultName(t *testing.T) { d := initTestMotorDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Motor"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Motor")) } func TestMotorDriverSetName(t *testing.T) { d := initTestMotorDriver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/pir_motion_driver_test.go b/drivers/gpio/pir_motion_driver_test.go index 6cfc755b1..b7a7e87bc 100644 --- a/drivers/gpio/pir_motion_driver_test.go +++ b/drivers/gpio/pir_motion_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*PIRMotionDriver)(nil) @@ -23,15 +23,15 @@ func TestPIRMotionDriverHalt(t *testing.T) { go func() { <-d.halt }() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestPIRMotionDriver(t *testing.T) { d := NewPIRMotionDriver(newGpioTestAdaptor(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) d = NewPIRMotionDriver(newGpioTestAdaptor(), "1", 30*time.Second) - gobottest.Assert(t, d.interval, 30*time.Second) + assert.Equal(t, 30*time.Second, d.interval) } func TestPIRMotionDriverStart(t *testing.T) { @@ -39,10 +39,10 @@ func TestPIRMotionDriverStart(t *testing.T) { a := newGpioTestAdaptor() d := NewPIRMotionDriver(a, "1") - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) _ = d.Once(MotionDetected, func(data interface{}) { - gobottest.Assert(t, d.Active, true) + assert.True(t, d.Active) sem <- true }) @@ -58,7 +58,7 @@ func TestPIRMotionDriverStart(t *testing.T) { } _ = d.Once(MotionStopped, func(data interface{}) { - gobottest.Assert(t, d.Active, false) + assert.False(t, d.Active) sem <- true }) @@ -91,11 +91,11 @@ func TestPIRMotionDriverStart(t *testing.T) { func TestPIRDriverDefaultName(t *testing.T) { d := initTestPIRMotionDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "PIR"), true) + assert.True(t, strings.HasPrefix(d.Name(), "PIR")) } func TestPIRDriverSetName(t *testing.T) { d := initTestPIRMotionDriver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/relay_driver_test.go b/drivers/gpio/relay_driver_test.go index 12160357a..c920871f0 100644 --- a/drivers/gpio/relay_driver_test.go +++ b/drivers/gpio/relay_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*RelayDriver)(nil) @@ -26,24 +26,24 @@ func initTestRelayDriver() (*RelayDriver, *gpioTestAdaptor) { func TestRelayDriverDefaultName(t *testing.T) { g, _ := initTestRelayDriver() - gobottest.Refute(t, g.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(g.Name(), "Relay"), true) + assert.NotNil(t, g.Connection()) + assert.True(t, strings.HasPrefix(g.Name(), "Relay")) } func TestRelayDriverSetName(t *testing.T) { g, _ := initTestRelayDriver() g.SetName("mybot") - gobottest.Assert(t, g.Name(), "mybot") + assert.Equal(t, "mybot", g.Name()) } func TestRelayDriverStart(t *testing.T) { d, _ := initTestRelayDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestRelayDriverHalt(t *testing.T) { d, _ := initTestRelayDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestRelayDriverToggle(t *testing.T) { @@ -55,14 +55,14 @@ func TestRelayDriverToggle(t *testing.T) { }) _ = d.Off() - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(0)) + assert.False(t, d.State()) + assert.Equal(t, byte(0), lastVal) _ = d.Toggle() - gobottest.Assert(t, d.State(), true) - gobottest.Assert(t, lastVal, byte(1)) + assert.True(t, d.State()) + assert.Equal(t, byte(1), lastVal) _ = d.Toggle() - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(0)) + assert.False(t, d.State()) + assert.Equal(t, byte(0), lastVal) } func TestRelayDriverToggleInverted(t *testing.T) { @@ -75,14 +75,14 @@ func TestRelayDriverToggleInverted(t *testing.T) { d.Inverted = true _ = d.Off() - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(1)) + assert.False(t, d.State()) + assert.Equal(t, byte(1), lastVal) _ = d.Toggle() - gobottest.Assert(t, d.State(), true) - gobottest.Assert(t, lastVal, byte(0)) + assert.True(t, d.State()) + assert.Equal(t, byte(0), lastVal) _ = d.Toggle() - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(1)) + assert.False(t, d.State()) + assert.Equal(t, byte(1), lastVal) } func TestRelayDriverCommands(t *testing.T) { @@ -93,17 +93,17 @@ func TestRelayDriverCommands(t *testing.T) { return nil }) - gobottest.Assert(t, d.Command("Off")(nil), nil) - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(0)) + assert.Nil(t, d.Command("Off")(nil)) + assert.False(t, d.State()) + assert.Equal(t, byte(0), lastVal) - gobottest.Assert(t, d.Command("On")(nil), nil) - gobottest.Assert(t, d.State(), true) - gobottest.Assert(t, lastVal, byte(1)) + assert.Nil(t, d.Command("On")(nil)) + assert.True(t, d.State()) + assert.Equal(t, byte(1), lastVal) - gobottest.Assert(t, d.Command("Toggle")(nil), nil) - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(0)) + assert.Nil(t, d.Command("Toggle")(nil)) + assert.False(t, d.State()) + assert.Equal(t, byte(0), lastVal) } func TestRelayDriverCommandsInverted(t *testing.T) { @@ -115,18 +115,18 @@ func TestRelayDriverCommandsInverted(t *testing.T) { }) d.Inverted = true - gobottest.Assert(t, d.Command("Off")(nil), nil) - gobottest.Assert(t, d.High(), true) - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(1)) + assert.Nil(t, d.Command("Off")(nil)) + assert.True(t, d.High()) + assert.False(t, d.State()) + assert.Equal(t, byte(1), lastVal) - gobottest.Assert(t, d.Command("On")(nil), nil) - gobottest.Assert(t, d.High(), false) - gobottest.Assert(t, d.State(), true) - gobottest.Assert(t, lastVal, byte(0)) + assert.Nil(t, d.Command("On")(nil)) + assert.False(t, d.High()) + assert.True(t, d.State()) + assert.Equal(t, byte(0), lastVal) - gobottest.Assert(t, d.Command("Toggle")(nil), nil) - gobottest.Assert(t, d.High(), true) - gobottest.Assert(t, d.State(), false) - gobottest.Assert(t, lastVal, byte(1)) + assert.Nil(t, d.Command("Toggle")(nil)) + assert.True(t, d.High()) + assert.False(t, d.State()) + assert.Equal(t, byte(1), lastVal) } diff --git a/drivers/gpio/rgb_led_driver_test.go b/drivers/gpio/rgb_led_driver_test.go index 2e9ffc9ca..5173b02ee 100644 --- a/drivers/gpio/rgb_led_driver_test.go +++ b/drivers/gpio/rgb_led_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*RgbLedDriver)(nil) @@ -28,11 +28,11 @@ func TestRgbLedDriver(t *testing.T) { a := newGpioTestAdaptor() d := NewRgbLedDriver(a, "1", "2", "3") - gobottest.Assert(t, d.Pin(), "r=1, g=2, b=3") - gobottest.Assert(t, d.RedPin(), "1") - gobottest.Assert(t, d.GreenPin(), "2") - gobottest.Assert(t, d.BluePin(), "3") - gobottest.Refute(t, d.Connection(), nil) + assert.Equal(t, "r=1, g=2, b=3", d.Pin()) + assert.Equal(t, "1", d.RedPin()) + assert.Equal(t, "2", d.GreenPin()) + assert.Equal(t, "3", d.BluePin()) + assert.NotNil(t, d.Connection()) a.testAdaptorDigitalWrite = func(string, byte) (err error) { return errors.New("write error") @@ -42,59 +42,59 @@ func TestRgbLedDriver(t *testing.T) { } err = d.Command("Toggle")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("On")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("Off")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("SetRGB")(map[string]interface{}{"r": 0xff, "g": 0xff, "b": 0xff}) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") } func TestRgbLedDriverStart(t *testing.T) { d := initTestRgbLedDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestRgbLedDriverHalt(t *testing.T) { d := initTestRgbLedDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestRgbLedDriverToggle(t *testing.T) { d := initTestRgbLedDriver() _ = d.Off() _ = d.Toggle() - gobottest.Assert(t, d.State(), true) + assert.True(t, d.State()) _ = d.Toggle() - gobottest.Assert(t, d.State(), false) + assert.False(t, d.State()) } func TestRgbLedDriverSetLevel(t *testing.T) { a := newGpioTestAdaptor() d := NewRgbLedDriver(a, "1", "2", "3") - gobottest.Assert(t, d.SetLevel("1", 150), nil) + assert.Nil(t, d.SetLevel("1", 150)) d = NewRgbLedDriver(a, "1", "2", "3") a.testAdaptorPwmWrite = func(string, byte) (err error) { err = errors.New("pwm error") return } - gobottest.Assert(t, d.SetLevel("1", 150), errors.New("pwm error")) + assert.Errorf(t, d.SetLevel("1", 150), "pwm error") } func TestRgbLedDriverDefaultName(t *testing.T) { a := newGpioTestAdaptor() d := NewRgbLedDriver(a, "1", "2", "3") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "RGB"), true) + assert.True(t, strings.HasPrefix(d.Name(), "RGB")) } func TestRgbLedDriverSetName(t *testing.T) { a := newGpioTestAdaptor() d := NewRgbLedDriver(a, "1", "2", "3") d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/servo_driver_test.go b/drivers/gpio/servo_driver_test.go index d34094d4b..0d3058b66 100644 --- a/drivers/gpio/servo_driver_test.go +++ b/drivers/gpio/servo_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*ServoDriver)(nil) @@ -21,69 +21,69 @@ func TestServoDriver(t *testing.T) { a := newGpioTestAdaptor() d := NewServoDriver(a, "1") - gobottest.Assert(t, d.Pin(), "1") - gobottest.Refute(t, d.Connection(), nil) + assert.Equal(t, "1", d.Pin()) + assert.NotNil(t, d.Connection()) a.testAdaptorServoWrite = func(string, byte) (err error) { return errors.New("pwm error") } err = d.Command("Min")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("Center")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("Max")(nil) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") err = d.Command("Move")(map[string]interface{}{"angle": 100.0}) - gobottest.Assert(t, err.(error), errors.New("pwm error")) + assert.Errorf(t, err.(error), "pwm error") } func TestServoDriverStart(t *testing.T) { d := initTestServoDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestServoDriverHalt(t *testing.T) { d := initTestServoDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestServoDriverMove(t *testing.T) { d := initTestServoDriver() _ = d.Move(100) - gobottest.Assert(t, d.CurrentAngle, uint8(100)) + assert.Equal(t, uint8(100), d.CurrentAngle) err := d.Move(200) - gobottest.Assert(t, err, ErrServoOutOfRange) + assert.Equal(t, ErrServoOutOfRange, err) } func TestServoDriverMin(t *testing.T) { d := initTestServoDriver() _ = d.Min() - gobottest.Assert(t, d.CurrentAngle, uint8(0)) + assert.Equal(t, uint8(0), d.CurrentAngle) } func TestServoDriverMax(t *testing.T) { d := initTestServoDriver() _ = d.Max() - gobottest.Assert(t, d.CurrentAngle, uint8(180)) + assert.Equal(t, uint8(180), d.CurrentAngle) } func TestServoDriverCenter(t *testing.T) { d := initTestServoDriver() _ = d.Center() - gobottest.Assert(t, d.CurrentAngle, uint8(90)) + assert.Equal(t, uint8(90), d.CurrentAngle) } func TestServoDriverDefaultName(t *testing.T) { d := initTestServoDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Servo"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Servo")) } func TestServoDriverSetName(t *testing.T) { d := initTestServoDriver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } diff --git a/drivers/gpio/stepper_driver_test.go b/drivers/gpio/stepper_driver_test.go index d41449c30..9e88dd693 100644 --- a/drivers/gpio/stepper_driver_test.go +++ b/drivers/gpio/stepper_driver_test.go @@ -1,12 +1,11 @@ package gpio import ( - "errors" "strings" "testing" "time" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) const ( @@ -20,7 +19,7 @@ func initStepperMotorDriver() *StepperDriver { func TestStepperDriverRun(t *testing.T) { d := initStepperMotorDriver() _ = d.Run() - gobottest.Assert(t, d.IsMoving(), true) + assert.True(t, d.IsMoving()) } func TestStepperDriverHalt(t *testing.T) { @@ -28,61 +27,61 @@ func TestStepperDriverHalt(t *testing.T) { _ = d.Run() time.Sleep(200 * time.Millisecond) _ = d.Halt() - gobottest.Assert(t, d.IsMoving(), false) + assert.False(t, d.IsMoving()) } func TestStepperDriverDefaultName(t *testing.T) { d := initStepperMotorDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Stepper"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Stepper")) } func TestStepperDriverSetName(t *testing.T) { name := "SomeStepperSriver" d := initStepperMotorDriver() d.SetName(name) - gobottest.Assert(t, d.Name(), name) + assert.Equal(t, name, d.Name()) } func TestStepperDriverSetDirection(t *testing.T) { dir := "backward" d := initStepperMotorDriver() _ = d.SetDirection(dir) - gobottest.Assert(t, d.direction, dir) + assert.Equal(t, dir, d.direction) } func TestStepperDriverDefaultDirection(t *testing.T) { d := initStepperMotorDriver() - gobottest.Assert(t, d.direction, "forward") + assert.Equal(t, "forward", d.direction) } func TestStepperDriverInvalidDirection(t *testing.T) { d := initStepperMotorDriver() err := d.SetDirection("reverse") - gobottest.Assert(t, err, errors.New("Invalid direction. Value should be forward or backward")) + assert.Errorf(t, err, "Invalid direction. Value should be forward or backward") } func TestStepperDriverMoveForward(t *testing.T) { d := initStepperMotorDriver() _ = d.Move(1) - gobottest.Assert(t, d.GetCurrentStep(), 1) + assert.Equal(t, 1, d.GetCurrentStep()) _ = d.Move(10) - gobottest.Assert(t, d.GetCurrentStep(), 11) + assert.Equal(t, 11, d.GetCurrentStep()) } func TestStepperDriverMoveBackward(t *testing.T) { d := initStepperMotorDriver() _ = d.Move(-1) - gobottest.Assert(t, d.GetCurrentStep(), stepsInRev-1) + assert.Equal(t, stepsInRev-1, d.GetCurrentStep()) _ = d.Move(-10) - gobottest.Assert(t, d.GetCurrentStep(), stepsInRev-11) + assert.Equal(t, stepsInRev-11, d.GetCurrentStep()) } func TestStepperDriverMoveFullRotation(t *testing.T) { d := initStepperMotorDriver() _ = d.Move(stepsInRev) - gobottest.Assert(t, d.GetCurrentStep(), 0) + assert.Equal(t, 0, d.GetCurrentStep()) } func TestStepperDriverMotorSetSpeedMoreThanMax(t *testing.T) { @@ -90,7 +89,7 @@ func TestStepperDriverMotorSetSpeedMoreThanMax(t *testing.T) { m := d.GetMaxSpeed() _ = d.SetSpeed(m + 1) - gobottest.Assert(t, m, d.speed) + assert.Equal(t, d.speed, m) } func TestStepperDriverMotorSetSpeedLessOrEqualMax(t *testing.T) { @@ -98,8 +97,8 @@ func TestStepperDriverMotorSetSpeedLessOrEqualMax(t *testing.T) { m := d.GetMaxSpeed() _ = d.SetSpeed(m - 1) - gobottest.Assert(t, m-1, d.speed) + assert.Equal(t, d.speed, m-1) _ = d.SetSpeed(m) - gobottest.Assert(t, m, d.speed) + assert.Equal(t, d.speed, m) } diff --git a/drivers/gpio/tm1638_driver_test.go b/drivers/gpio/tm1638_driver_test.go index ccff9152e..e7e5b7682 100644 --- a/drivers/gpio/tm1638_driver_test.go +++ b/drivers/gpio/tm1638_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*TM1638Driver)(nil) @@ -32,41 +32,41 @@ func TestTM1638Driver(t *testing.T) { func TestTM1638DriverStart(t *testing.T) { d := initTestTM1638Driver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestTM1638DriverHalt(t *testing.T) { d := initTestTM1638Driver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestTM1638DriverDefaultName(t *testing.T) { d := initTestTM1638Driver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "TM1638"), true) + assert.True(t, strings.HasPrefix(d.Name(), "TM1638")) } func TestTM1638DriverSetName(t *testing.T) { d := initTestTM1638Driver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } func TestTM1638DriverFromStringToByteArray(t *testing.T) { d := initTestTM1638Driver() data := d.fromStringToByteArray("Hello World") - gobottest.Assert(t, []byte{0x76, 0x7B, 0x30, 0x30, 0x5C, 0x00, 0x1D, 0x5C, 0x50, 0x30, 0x5E}, data) + assert.Equal(t, data, []byte{0x76, 0x7B, 0x30, 0x30, 0x5C, 0x00, 0x1D, 0x5C, 0x50, 0x30, 0x5E}) } func TestTM1638DriverAddFonts(t *testing.T) { d := initTestTM1638Driver() d.AddFonts(map[string]byte{"µ": 0x1C, "ß": 0x7F}) data := d.fromStringToByteArray("µß") - gobottest.Assert(t, []byte{0x1C, 0x7F}, data) + assert.Equal(t, data, []byte{0x1C, 0x7F}) } func TestTM1638DriverClearFonts(t *testing.T) { d := initTestTM1638Driver() d.ClearFonts() data := d.fromStringToByteArray("Hello World") - gobottest.Assert(t, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, data) + assert.Equal(t, data, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) } diff --git a/drivers/i2c/adafruit1109_driver_test.go b/drivers/i2c/adafruit1109_driver_test.go index 8fcb5a94d..f2c901374 100644 --- a/drivers/i2c/adafruit1109_driver_test.go +++ b/drivers/i2c/adafruit1109_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Adafruit1109Driver)(nil) @@ -23,49 +23,49 @@ func TestNewAdafruit1109Driver(t *testing.T) { if !ok { t.Errorf("NewAdafruit1109Driver() should have returned a *Adafruit1109Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Refute(t, d.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Adafruit1109"), true) - gobottest.Assert(t, strings.Contains(d.Name(), "MCP23017"), true) - gobottest.Assert(t, strings.Contains(d.Name(), "HD44780"), true) - gobottest.Refute(t, d.MCP23017Driver, nil) - gobottest.Refute(t, d.HD44780Driver, nil) - gobottest.Refute(t, d.redPin, nil) - gobottest.Refute(t, d.greenPin, nil) - gobottest.Refute(t, d.bluePin, nil) - gobottest.Refute(t, d.selectPin, nil) - gobottest.Refute(t, d.upPin, nil) - gobottest.Refute(t, d.downPin, nil) - gobottest.Refute(t, d.leftPin, nil) - gobottest.Refute(t, d.rightPin, nil) - gobottest.Refute(t, d.rwPin, nil) - gobottest.Refute(t, d.rsPin, nil) - gobottest.Refute(t, d.enPin, nil) - gobottest.Refute(t, d.dataPinD4, nil) - gobottest.Refute(t, d.dataPinD5, nil) - gobottest.Refute(t, d.dataPinD6, nil) - gobottest.Refute(t, d.dataPinD7, nil) + assert.NotNil(t, d.Driver) + assert.NotNil(t, d.Connection()) + assert.True(t, strings.HasPrefix(d.Name(), "Adafruit1109")) + assert.Contains(t, d.Name(), "MCP23017") + assert.Contains(t, d.Name(), "HD44780") + assert.NotNil(t, d.MCP23017Driver) + assert.NotNil(t, d.HD44780Driver) + assert.NotNil(t, d.redPin) + assert.NotNil(t, d.greenPin) + assert.NotNil(t, d.bluePin) + assert.NotNil(t, d.selectPin) + assert.NotNil(t, d.upPin) + assert.NotNil(t, d.downPin) + assert.NotNil(t, d.leftPin) + assert.NotNil(t, d.rightPin) + assert.NotNil(t, d.rwPin) + assert.NotNil(t, d.rsPin) + assert.NotNil(t, d.enPin) + assert.NotNil(t, d.dataPinD4) + assert.NotNil(t, d.dataPinD5) + assert.NotNil(t, d.dataPinD6) + assert.NotNil(t, d.dataPinD7) } func TestAdafruit1109Connect(t *testing.T) { d, _ := initTestAdafruit1109WithStubbedAdaptor() - gobottest.Assert(t, d.Connect(), nil) + assert.Nil(t, d.Connect()) } func TestAdafruit1109Finalize(t *testing.T) { d, _ := initTestAdafruit1109WithStubbedAdaptor() - gobottest.Assert(t, d.Finalize(), nil) + assert.Nil(t, d.Finalize()) } func TestAdafruit1109SetName(t *testing.T) { d, _ := initTestAdafruit1109WithStubbedAdaptor() d.SetName("foo") - gobottest.Assert(t, d.name, "foo") + assert.Equal(t, "foo", d.name) } func TestAdafruit1109Start(t *testing.T) { d, _ := initTestAdafruit1109WithStubbedAdaptor() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestAdafruit1109StartWriteErr(t *testing.T) { @@ -73,7 +73,7 @@ func TestAdafruit1109StartWriteErr(t *testing.T) { adaptor.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Start(), errors.New("write error")) + assert.Errorf(t, d.Start(), "write error") } func TestAdafruit1109StartReadErr(t *testing.T) { @@ -81,13 +81,13 @@ func TestAdafruit1109StartReadErr(t *testing.T) { adaptor.i2cReadImpl = func([]byte) (int, error) { return 0, errors.New("read error") } - gobottest.Assert(t, d.Start(), errors.New("MCP write-read: MCP write-ReadByteData(reg=0): read error")) + assert.Errorf(t, d.Start(), "MCP write-read: MCP write-ReadByteData(reg=0): read error") } func TestAdafruit1109Halt(t *testing.T) { d, _ := initTestAdafruit1109WithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestAdafruit1109DigitalRead(t *testing.T) { @@ -128,11 +128,11 @@ func TestAdafruit1109DigitalRead(t *testing.T) { // act got, err := d.DigitalRead(name) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], tc.wantReg) - gobottest.Assert(t, got, 1) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, tc.wantReg, a.written[0]) + assert.Equal(t, 1, got) }) } } @@ -160,9 +160,9 @@ func TestAdafruit1109SelectButton(t *testing.T) { // act got, err := d.SelectButton() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, tc.want, got) }) } } @@ -190,9 +190,9 @@ func TestAdafruit1109UpButton(t *testing.T) { // act got, err := d.UpButton() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, tc.want, got) }) } } @@ -220,9 +220,9 @@ func TestAdafruit1109DownButton(t *testing.T) { // act got, err := d.DownButton() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, tc.want, got) }) } } @@ -250,9 +250,9 @@ func TestAdafruit1109LeftButton(t *testing.T) { // act got, err := d.LeftButton() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, tc.want, got) }) } } @@ -280,9 +280,9 @@ func TestAdafruit1109RightButton(t *testing.T) { // act got, err := d.RightButton() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, tc.want, got) }) } } @@ -297,7 +297,7 @@ func TestAdafruit1109_parseID(t *testing.T) { // act got := adafruit1109ParseID(id) // assert - gobottest.Assert(t, got, adafruit1109PortPin{port, pin}) + assert.Equal(t, adafruit1109PortPin{port, pin}, got) }) } } diff --git a/drivers/i2c/adafruit_driver_test.go b/drivers/i2c/adafruit_driver_test.go index 4f2bbd6b2..d100a73fe 100644 --- a/drivers/i2c/adafruit_driver_test.go +++ b/drivers/i2c/adafruit_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation implements the gobot.Driver interface @@ -30,14 +30,14 @@ func TestNewAdafruitMotorHatDriver(t *testing.T) { if !ok { t.Errorf("AdafruitMotorHatDriver() should have returned a *AdafruitMotorHatDriver") } - gobottest.Assert(t, strings.HasPrefix(d.Name(), "AdafruitMotorHat"), true) + assert.True(t, strings.HasPrefix(d.Name(), "AdafruitMotorHat")) } // Methods func TestAdafruitMotorHatDriverStart(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Refute(t, ada.Connection(), nil) - gobottest.Assert(t, ada.Start(), nil) + assert.NotNil(t, ada.Connection()) + assert.Nil(t, ada.Start()) } func TestAdafruitMotorHatDriverStartWriteError(t *testing.T) { @@ -45,7 +45,7 @@ func TestAdafruitMotorHatDriverStartWriteError(t *testing.T) { adaptor.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Start(), errors.New("write error")) + assert.Errorf(t, d.Start(), "write error") } func TestAdafruitMotorHatDriverStartReadError(t *testing.T) { @@ -53,19 +53,19 @@ func TestAdafruitMotorHatDriverStartReadError(t *testing.T) { adaptor.i2cReadImpl = func([]byte) (int, error) { return 0, errors.New("read error") } - gobottest.Assert(t, d.Start(), errors.New("read error")) + assert.Errorf(t, d.Start(), "read error") } func TestAdafruitMotorHatDriverStartConnectError(t *testing.T) { d, adaptor := initTestAdafruitMotorHatDriverWithStubbedAdaptor() adaptor.Testi2cConnectErr(true) - gobottest.Assert(t, d.Start(), errors.New("Invalid i2c connection")) + assert.Errorf(t, d.Start(), "Invalid i2c connection") } func TestAdafruitMotorHatDriverHalt(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Halt(), nil) + assert.Nil(t, ada.Halt()) } func TestSetHatAddresses(t *testing.T) { @@ -73,48 +73,48 @@ func TestSetHatAddresses(t *testing.T) { motorHatAddr := 0x61 servoHatAddr := 0x41 - gobottest.Assert(t, ada.SetMotorHatAddress(motorHatAddr), nil) - gobottest.Assert(t, ada.SetServoHatAddress(servoHatAddr), nil) + assert.Nil(t, ada.SetMotorHatAddress(motorHatAddr)) + assert.Nil(t, ada.SetServoHatAddress(servoHatAddr)) } func TestAdafruitMotorHatDriverSetServoMotorFreq(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) freq := 60.0 err := ada.SetServoMotorFreq(freq) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverSetServoMotorFreqError(t *testing.T) { ada, a := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } freq := 60.0 - gobottest.Assert(t, ada.SetServoMotorFreq(freq), errors.New("write error")) + assert.Errorf(t, ada.SetServoMotorFreq(freq), "write error") } func TestAdafruitMotorHatDriverSetServoMotorPulse(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) var channel byte = 7 var on int32 = 1234 var off int32 = 4321 err := ada.SetServoMotorPulse(channel, on, off) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverSetServoMotorPulseError(t *testing.T) { ada, a := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } @@ -122,124 +122,124 @@ func TestAdafruitMotorHatDriverSetServoMotorPulseError(t *testing.T) { var channel byte = 7 var on int32 = 1234 var off int32 = 4321 - gobottest.Assert(t, ada.SetServoMotorPulse(channel, on, off), errors.New("write error")) + assert.Errorf(t, ada.SetServoMotorPulse(channel, on, off), "write error") } func TestAdafruitMotorHatDriverSetDCMotorSpeed(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) dcMotor := 1 var speed int32 = 255 err := ada.SetDCMotorSpeed(dcMotor, speed) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverSetDCMotorSpeedError(t *testing.T) { ada, a := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, ada.SetDCMotorSpeed(1, 255), errors.New("write error")) + assert.Errorf(t, ada.SetDCMotorSpeed(1, 255), "write error") } func TestAdafruitMotorHatDriverRunDCMotor(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) dcMotor := 1 - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitForward), nil) - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitBackward), nil) - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitRelease), nil) + assert.Nil(t, ada.RunDCMotor(dcMotor, AdafruitForward)) + assert.Nil(t, ada.RunDCMotor(dcMotor, AdafruitBackward)) + assert.Nil(t, ada.RunDCMotor(dcMotor, AdafruitRelease)) } func TestAdafruitMotorHatDriverRunDCMotorError(t *testing.T) { ada, a := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } dcMotor := 1 - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitForward), errors.New("write error")) - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitBackward), errors.New("write error")) - gobottest.Assert(t, ada.RunDCMotor(dcMotor, AdafruitRelease), errors.New("write error")) + assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitForward), "write error") + assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitBackward), "write error") + assert.Errorf(t, ada.RunDCMotor(dcMotor, AdafruitRelease), "write error") } func TestAdafruitMotorHatDriverSetStepperMotorSpeed(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) stepperMotor := 1 rpm := 30 - gobottest.Assert(t, ada.SetStepperMotorSpeed(stepperMotor, rpm), nil) + assert.Nil(t, ada.SetStepperMotorSpeed(stepperMotor, rpm)) } func TestAdafruitMotorHatDriverStepperMicroStep(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) // NOTE: not using the direction and style constants to prevent importing // the i2c package stepperMotor := 0 steps := 50 err := ada.Step(stepperMotor, steps, 1, 3) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverStepperSingleStep(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) // NOTE: not using the direction and style constants to prevent importing // the i2c package stepperMotor := 0 steps := 50 err := ada.Step(stepperMotor, steps, 1, 0) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverStepperDoubleStep(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) // NOTE: not using the direction and style constants to prevent importing // the i2c package stepperMotor := 0 steps := 50 err := ada.Step(stepperMotor, steps, 1, 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverStepperInterleaveStep(t *testing.T) { ada, _ := initTestAdafruitMotorHatDriverWithStubbedAdaptor() - gobottest.Assert(t, ada.Start(), nil) + assert.Nil(t, ada.Start()) // NOTE: not using the direction and style constants to prevent importing // the i2c package stepperMotor := 0 steps := 50 err := ada.Step(stepperMotor, steps, 1, 2) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestAdafruitMotorHatDriverSetName(t *testing.T) { d := initTestAdafruitMotorHatDriver() d.SetName("TESTME") - gobottest.Assert(t, d.Name(), "TESTME") + assert.Equal(t, "TESTME", d.Name()) } func TestAdafruitMotorHatDriverOptions(t *testing.T) { d := NewAdafruitMotorHatDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } diff --git a/drivers/i2c/ads1x15_driver_1015_test.go b/drivers/i2c/ads1x15_driver_1015_test.go index 8e009bcd6..ef882fa39 100644 --- a/drivers/i2c/ads1x15_driver_1015_test.go +++ b/drivers/i2c/ads1x15_driver_1015_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func initTestADS1015DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) { @@ -23,11 +23,11 @@ func TestNewADS1015Driver(t *testing.T) { if !ok { t.Errorf("NewADS1015Driver() should have returned a *ADS1x15Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "ADS1015"), true) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "ADS1015")) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 1) - gobottest.Assert(t, d.channelCfgs[i].dataRate, 1600) + assert.Equal(t, 1, d.channelCfgs[i].gain) + assert.Equal(t, 1600, d.channelCfgs[i].dataRate) } } @@ -35,10 +35,10 @@ func TestADS1015Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewADS1015Driver(newI2cTestAdaptor(), WithBus(2), WithADS1x15Gain(2), WithADS1x15DataRate(920)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 2) - gobottest.Assert(t, d.channelCfgs[i].dataRate, 920) + assert.Equal(t, 2, d.channelCfgs[i].gain) + assert.Equal(t, 920, d.channelCfgs[i].dataRate) } } @@ -46,7 +46,7 @@ func TestADS1015WithADS1x15BestGainForVoltage(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() WithADS1x15BestGainForVoltage(1.01)(d) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 3) + assert.Equal(t, 3, d.channelCfgs[i].gain) } } @@ -56,10 +56,10 @@ func TestADS1015WithADS1x15ChannelBestGainForVoltage(t *testing.T) { WithADS1x15ChannelBestGainForVoltage(1, 2.5)(d) WithADS1x15ChannelBestGainForVoltage(2, 3.3)(d) WithADS1x15ChannelBestGainForVoltage(3, 5.0)(d) - gobottest.Assert(t, d.channelCfgs[0].gain, 3) - gobottest.Assert(t, d.channelCfgs[1].gain, 1) - gobottest.Assert(t, d.channelCfgs[2].gain, 1) - gobottest.Assert(t, d.channelCfgs[3].gain, 0) + assert.Equal(t, 3, d.channelCfgs[0].gain) + assert.Equal(t, 1, d.channelCfgs[1].gain) + assert.Equal(t, 1, d.channelCfgs[2].gain) + assert.Equal(t, 0, d.channelCfgs[3].gain) } func TestADS1015AnalogRead(t *testing.T) { @@ -72,39 +72,39 @@ func TestADS1015AnalogRead(t *testing.T) { } val, err := d.AnalogRead("0") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("1") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("2") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("0-1") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("0-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("1-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("2-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) _, err = d.AnalogRead("3-2") - gobottest.Refute(t, err.Error(), nil) + assert.NotNil(t, err.Error()) } func TestADS1x15AnalogReadError(t *testing.T) { @@ -115,14 +115,14 @@ func TestADS1x15AnalogReadError(t *testing.T) { } _, err := d.AnalogRead("0") - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestADS1x15AnalogReadInvalidPin(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() _, err := d.AnalogRead("99") - gobottest.Assert(t, err, errors.New("Invalid channel (99), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (99), must be between 0 and 3") } func TestADS1x15AnalogReadWriteError(t *testing.T) { @@ -133,41 +133,41 @@ func TestADS1x15AnalogReadWriteError(t *testing.T) { } _, err := d.AnalogRead("0") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") _, err = d.AnalogRead("0-1") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") _, err = d.AnalogRead("2-3") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestADS1x15ReadInvalidChannel(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() _, err := d.Read(9, 1, 1600) - gobottest.Assert(t, err, errors.New("Invalid channel (9), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (9), must be between 0 and 3") } func TestADS1x15ReadInvalidGain(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() _, err := d.Read(0, 8, 1600) - gobottest.Assert(t, err, errors.New("Gain (8) must be one of: [0 1 2 3 4 5 6 7]")) + assert.Errorf(t, err, "Gain (8) must be one of: [0 1 2 3 4 5 6 7]") } func TestADS1x15ReadInvalidDataRate(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() _, err := d.Read(0, 1, 321) - gobottest.Assert(t, err, errors.New("Invalid data rate (321). Accepted values: [128 250 490 920 1600 2400 3300]")) + assert.Errorf(t, err, "Invalid data rate (321). Accepted values: [128 250 490 920 1600 2400 3300]") } func TestADS1x15ReadDifferenceInvalidChannel(t *testing.T) { d, _ := initTestADS1015DriverWithStubbedAdaptor() _, err := d.ReadDifference(9, 1, 1600) - gobottest.Assert(t, err, errors.New("Invalid channel (9), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (9), must be between 0 and 3") } func TestADS1015_rawRead(t *testing.T) { @@ -269,16 +269,16 @@ func TestADS1015_rawRead(t *testing.T) { // act got, err := d.rawRead(channel, channelOffset, tt.gain, tt.dataRate) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) - gobottest.Assert(t, numCallsRead, 3) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], uint8(ads1x15PointerConfig)) - gobottest.Assert(t, a.written[1], tt.wantConfig[0]) // MSByte: OS, MUX, PGA, MODE - gobottest.Assert(t, a.written[2], tt.wantConfig[1]) // LSByte: DR, COMP_* - gobottest.Assert(t, a.written[3], uint8(ads1x15PointerConfig)) // first check for no conversion - gobottest.Assert(t, a.written[4], uint8(ads1x15PointerConfig)) // second check for no conversion - gobottest.Assert(t, a.written[5], uint8(ads1x15PointerConversion)) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + assert.Equal(t, 3, numCallsRead) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[0]) + assert.Equal(t, tt.wantConfig[0], a.written[1]) // MSByte: OS, MUX, PGA, MODE + assert.Equal(t, tt.wantConfig[1], a.written[2]) // LSByte: DR, COMP_* + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[3]) // first check for no conversion + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[4]) // second check for no conversion + assert.Equal(t, uint8(ads1x15PointerConversion), a.written[5]) }) } } diff --git a/drivers/i2c/ads1x15_driver_1115_test.go b/drivers/i2c/ads1x15_driver_1115_test.go index 617d39fa7..5b3e5559c 100644 --- a/drivers/i2c/ads1x15_driver_1115_test.go +++ b/drivers/i2c/ads1x15_driver_1115_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func initTestADS1115DriverWithStubbedAdaptor() (*ADS1x15Driver, *i2cTestAdaptor) { @@ -23,11 +23,11 @@ func TestNewADS1115Driver(t *testing.T) { if !ok { t.Errorf("NewADS1115Driver() should have returned a *ADS1x15Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "ADS1115"), true) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "ADS1115")) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 1) - gobottest.Assert(t, d.channelCfgs[i].dataRate, 128) + assert.Equal(t, 1, d.channelCfgs[i].gain) + assert.Equal(t, 128, d.channelCfgs[i].dataRate) } } @@ -35,10 +35,10 @@ func TestADS1115Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewADS1115Driver(newI2cTestAdaptor(), WithBus(2), WithADS1x15Gain(2), WithADS1x15DataRate(860)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 2) - gobottest.Assert(t, d.channelCfgs[i].dataRate, 860) + assert.Equal(t, 2, d.channelCfgs[i].gain) + assert.Equal(t, 860, d.channelCfgs[i].dataRate) } } @@ -46,7 +46,7 @@ func TestADS1115WithADS1x15BestGainForVoltage(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() WithADS1x15BestGainForVoltage(1.01)(d) for i := 0; i <= 3; i++ { - gobottest.Assert(t, d.channelCfgs[i].gain, 3) + assert.Equal(t, 3, d.channelCfgs[i].gain) } } @@ -56,10 +56,10 @@ func TestADS1115WithADS1x15ChannelBestGainForVoltage(t *testing.T) { WithADS1x15ChannelBestGainForVoltage(1, 2.5)(d) WithADS1x15ChannelBestGainForVoltage(2, 3.3)(d) WithADS1x15ChannelBestGainForVoltage(3, 5.0)(d) - gobottest.Assert(t, d.channelCfgs[0].gain, 3) - gobottest.Assert(t, d.channelCfgs[1].gain, 1) - gobottest.Assert(t, d.channelCfgs[2].gain, 1) - gobottest.Assert(t, d.channelCfgs[3].gain, 0) + assert.Equal(t, 3, d.channelCfgs[0].gain) + assert.Equal(t, 1, d.channelCfgs[1].gain) + assert.Equal(t, 1, d.channelCfgs[2].gain) + assert.Equal(t, 0, d.channelCfgs[3].gain) } func TestADS1115AnalogRead(t *testing.T) { @@ -72,39 +72,39 @@ func TestADS1115AnalogRead(t *testing.T) { } val, err := d.AnalogRead("0") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("1") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("2") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("0-1") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("0-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("1-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) val, err = d.AnalogRead("2-3") - gobottest.Assert(t, val, 32767) - gobottest.Assert(t, err, nil) + assert.Equal(t, 32767, val) + assert.Nil(t, err) _, err = d.AnalogRead("3-2") - gobottest.Refute(t, err.Error(), nil) + assert.NotNil(t, err.Error()) } func TestADS1115AnalogReadError(t *testing.T) { @@ -115,14 +115,14 @@ func TestADS1115AnalogReadError(t *testing.T) { } _, err := d.AnalogRead("0") - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestADS1115AnalogReadInvalidPin(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() _, err := d.AnalogRead("98") - gobottest.Assert(t, err, errors.New("Invalid channel (98), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (98), must be between 0 and 3") } func TestADS1115AnalogReadWriteError(t *testing.T) { @@ -133,41 +133,41 @@ func TestADS1115AnalogReadWriteError(t *testing.T) { } _, err := d.AnalogRead("0") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") _, err = d.AnalogRead("0-1") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") _, err = d.AnalogRead("2-3") - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestADS1115ReadInvalidChannel(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() _, err := d.Read(7, 1, 1600) - gobottest.Assert(t, err, errors.New("Invalid channel (7), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (7), must be between 0 and 3") } func TestADS1115ReadInvalidGain(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() _, err := d.Read(0, 21, 1600) - gobottest.Assert(t, err, errors.New("Gain (21) must be one of: [0 1 2 3 4 5 6 7]")) + assert.Errorf(t, err, "Gain (21) must be one of: [0 1 2 3 4 5 6 7]") } func TestADS1115ReadInvalidDataRate(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() _, err := d.Read(0, 1, 678) - gobottest.Assert(t, err, errors.New("Invalid data rate (678). Accepted values: [8 16 32 64 128 250 475 860]")) + assert.Errorf(t, err, "Invalid data rate (678). Accepted values: [8 16 32 64 128 250 475 860]") } func TestADS1115ReadDifferenceInvalidChannel(t *testing.T) { d, _ := initTestADS1115DriverWithStubbedAdaptor() _, err := d.ReadDifference(5, 1, 1600) - gobottest.Assert(t, err, errors.New("Invalid channel (5), must be between 0 and 3")) + assert.Errorf(t, err, "Invalid channel (5), must be between 0 and 3") } func TestADS1115_rawRead(t *testing.T) { @@ -269,16 +269,16 @@ func TestADS1115_rawRead(t *testing.T) { // act got, err := d.rawRead(channel, channelOffset, tt.gain, tt.dataRate) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tt.want) - gobottest.Assert(t, numCallsRead, 3) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], uint8(ads1x15PointerConfig)) - gobottest.Assert(t, a.written[1], tt.wantConfig[0]) // MSByte: OS, MUX, PGA, MODE - gobottest.Assert(t, a.written[2], tt.wantConfig[1]) // LSByte: DR, COMP_* - gobottest.Assert(t, a.written[3], uint8(ads1x15PointerConfig)) // first check for no conversion - gobottest.Assert(t, a.written[4], uint8(ads1x15PointerConfig)) // second check for no conversion - gobottest.Assert(t, a.written[5], uint8(ads1x15PointerConversion)) + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + assert.Equal(t, 3, numCallsRead) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[0]) + assert.Equal(t, tt.wantConfig[0], a.written[1]) // MSByte: OS, MUX, PGA, MODE + assert.Equal(t, tt.wantConfig[1], a.written[2]) // LSByte: DR, COMP_* + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[3]) // first check for no conversion + assert.Equal(t, uint8(ads1x15PointerConfig), a.written[4]) // second check for no conversion + assert.Equal(t, uint8(ads1x15PointerConversion), a.written[5]) }) } } diff --git a/drivers/i2c/ads1x15_driver_test.go b/drivers/i2c/ads1x15_driver_test.go index 948a36597..d842367f9 100644 --- a/drivers/i2c/ads1x15_driver_test.go +++ b/drivers/i2c/ads1x15_driver_test.go @@ -1,12 +1,11 @@ package i2c import ( - "errors" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/aio" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -48,8 +47,8 @@ func TestADS1x15CommandsReadDifferenceWithDefaults(t *testing.T) { // act result := d.Command("ReadDifferenceWithDefaults")(ads1x15TestChannel) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], -4.096) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, -4.096, result.(map[string]interface{})["val"]) } func TestADS1x15CommandsReadDifference(t *testing.T) { @@ -58,8 +57,8 @@ func TestADS1x15CommandsReadDifference(t *testing.T) { // act result := d.Command("ReadDifference")(ads1x15TestChannelGainDataRate) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], -2.048) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, -2.048, result.(map[string]interface{})["val"]) } func TestADS1x15CommandsReadWithDefaults(t *testing.T) { @@ -68,8 +67,8 @@ func TestADS1x15CommandsReadWithDefaults(t *testing.T) { // act result := d.Command("ReadWithDefaults")(ads1x15TestChannel) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], -4.096) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, -4.096, result.(map[string]interface{})["val"]) } func TestADS1x15CommandsRead(t *testing.T) { @@ -78,8 +77,8 @@ func TestADS1x15CommandsRead(t *testing.T) { // act result := d.Command("Read")(ads1x15TestChannelGainDataRate) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], -2.048) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, -2.048, result.(map[string]interface{})["val"]) } func TestADS1x15CommandsAnalogRead(t *testing.T) { @@ -91,14 +90,14 @@ func TestADS1x15CommandsAnalogRead(t *testing.T) { // act result := d.Command("AnalogRead")(ads1x15TestPin) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], -32768) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, -32768, result.(map[string]interface{})["val"]) } func TestADS1x15_ads1x15BestGainForVoltage(t *testing.T) { g, _ := ads1x15BestGainForVoltage(1.5) - gobottest.Assert(t, g, 2) + assert.Equal(t, 2, g) _, err := ads1x15BestGainForVoltage(20.0) - gobottest.Assert(t, err, errors.New("The maximum voltage which can be read is 6.144000")) + assert.Errorf(t, err, "The maximum voltage which can be read is 6.144000") } diff --git a/drivers/i2c/adxl345_driver_test.go b/drivers/i2c/adxl345_driver_test.go index d2f98f88c..c74f8104e 100644 --- a/drivers/i2c/adxl345_driver_test.go +++ b/drivers/i2c/adxl345_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -25,21 +25,21 @@ func TestNewADXL345Driver(t *testing.T) { if !ok { t.Errorf("NewADXL345Driver() should have returned a *ADXL345Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "ADXL345"), true) - gobottest.Assert(t, d.defaultAddress, 0x53) - gobottest.Assert(t, d.powerCtl.measure, uint8(1)) - gobottest.Assert(t, d.dataFormat.fullScaleRange, ADXL345FsRangeConfig(0x00)) - gobottest.Assert(t, d.bwRate.rate, ADXL345RateConfig(0x0A)) - gobottest.Assert(t, d.bwRate.lowPower, true) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "ADXL345")) + assert.Equal(t, 0x53, d.defaultAddress) + assert.Equal(t, uint8(1), d.powerCtl.measure) + assert.Equal(t, ADXL345FsRangeConfig(0x00), d.dataFormat.fullScaleRange) + assert.Equal(t, ADXL345RateConfig(0x0A), d.bwRate.rate) + assert.True(t, d.bwRate.lowPower) } func TestADXL345Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewADXL345Driver(newI2cTestAdaptor(), WithBus(2), WithADXL345LowPowerMode(false)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.bwRate.lowPower, false) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.False(t, d.bwRate.lowPower) } func TestADXL345WithADXL345DataOutputRate(t *testing.T) { @@ -52,8 +52,8 @@ func TestADXL345WithADXL345DataOutputRate(t *testing.T) { // act WithADXL345DataOutputRate(setVal)(d) // assert - gobottest.Assert(t, d.bwRate.rate, setVal) - gobottest.Assert(t, len(a.written), 0) + assert.Equal(t, setVal, d.bwRate.rate) + assert.Equal(t, 0, len(a.written)) } func TestADXL345WithADXL345FullScaleRange(t *testing.T) { @@ -66,8 +66,8 @@ func TestADXL345WithADXL345FullScaleRange(t *testing.T) { // act WithADXL345FullScaleRange(setVal)(d) // assert - gobottest.Assert(t, d.dataFormat.fullScaleRange, setVal) - gobottest.Assert(t, len(a.written), 0) + assert.Equal(t, setVal, d.dataFormat.fullScaleRange) + assert.Equal(t, 0, len(a.written)) } func TestADXL345UseLowPower(t *testing.T) { @@ -85,11 +85,11 @@ func TestADXL345UseLowPower(t *testing.T) { // act err := d.UseLowPower(setVal) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.bwRate.lowPower, setVal) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantVal) + assert.Nil(t, err) + assert.Equal(t, setVal, d.bwRate.lowPower) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantVal, a.written[1]) } func TestADXL345SetRate(t *testing.T) { @@ -107,11 +107,11 @@ func TestADXL345SetRate(t *testing.T) { // act err := d.SetRate(setVal) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.bwRate.rate, setVal) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantVal) + assert.Nil(t, err) + assert.Equal(t, setVal, d.bwRate.rate) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantVal, a.written[1]) } func TestADXL345SetRange(t *testing.T) { @@ -129,11 +129,11 @@ func TestADXL345SetRange(t *testing.T) { // act err := d.SetRange(setVal) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.dataFormat.fullScaleRange, setVal) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantVal) + assert.Nil(t, err) + assert.Equal(t, setVal, d.dataFormat.fullScaleRange) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantVal, a.written[1]) } func TestADXL345RawXYZ(t *testing.T) { @@ -184,13 +184,13 @@ func TestADXL345RawXYZ(t *testing.T) { // act gotX, gotY, gotZ, err := d.RawXYZ() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, gotX, tc.wantX) - gobottest.Assert(t, gotY, tc.wantY) - gobottest.Assert(t, gotZ, tc.wantZ) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x32)) + assert.Nil(t, err) + assert.Equal(t, tc.wantX, gotX) + assert.Equal(t, tc.wantY, gotY) + assert.Equal(t, tc.wantZ, gotZ) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x32), a.written[0]) }) } } @@ -205,7 +205,7 @@ func TestADXL345RawXYZError(t *testing.T) { // act _, _, _, err := d.RawXYZ() // assert - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestADXL345XYZ(t *testing.T) { @@ -252,9 +252,9 @@ func TestADXL345XYZ(t *testing.T) { // act x, y, z, _ := d.XYZ() // assert - gobottest.Assert(t, x, tc.wantX) - gobottest.Assert(t, y, tc.wantY) - gobottest.Assert(t, z, tc.wantZ) + assert.Equal(t, tc.wantX, x) + assert.Equal(t, tc.wantY, y) + assert.Equal(t, tc.wantZ, z) }) } } @@ -269,7 +269,7 @@ func TestADXL345XYZError(t *testing.T) { // act _, _, _, err := d.XYZ() // assert - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestADXL345_initialize(t *testing.T) { @@ -292,14 +292,14 @@ func TestADXL345_initialize(t *testing.T) { // act, assert - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], wantRateReg) - gobottest.Assert(t, a.written[1], wantRateRegVal) - gobottest.Assert(t, a.written[2], wantPwrReg) - gobottest.Assert(t, a.written[3], wantPwrRegVal) - gobottest.Assert(t, a.written[4], wantFormatReg) - gobottest.Assert(t, a.written[5], wantFormatRegVal) + assert.Nil(t, err) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, wantRateReg, a.written[0]) + assert.Equal(t, wantRateRegVal, a.written[1]) + assert.Equal(t, wantPwrReg, a.written[2]) + assert.Equal(t, wantPwrRegVal, a.written[3]) + assert.Equal(t, wantFormatReg, a.written[4]) + assert.Equal(t, wantFormatRegVal, a.written[5]) } func TestADXL345_shutdown(t *testing.T) { @@ -316,8 +316,8 @@ func TestADXL345_shutdown(t *testing.T) { // act, assert - shutdown() must be called on Halt() err := d.Halt() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantVal) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantVal, a.written[1]) } diff --git a/drivers/i2c/bh1750_driver_test.go b/drivers/i2c/bh1750_driver_test.go index 9d8fc94a1..a914d4407 100644 --- a/drivers/i2c/bh1750_driver_test.go +++ b/drivers/i2c/bh1750_driver_test.go @@ -7,8 +7,8 @@ import ( "bytes" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -30,32 +30,32 @@ func TestNewBH1750Driver(t *testing.T) { if !ok { t.Errorf("NewBH1750Driver() should have returned a *BH1750Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BH1750"), true) - gobottest.Assert(t, d.defaultAddress, 0x23) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BH1750")) + assert.Equal(t, 0x23, d.defaultAddress) } func TestBH1750Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewBH1750Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestBH1750Start(t *testing.T) { d := NewBH1750Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestBH1750Halt(t *testing.T) { d, _ := initTestBH1750DriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestBH1750NullLux(t *testing.T) { d, _ := initTestBH1750DriverWithStubbedAdaptor() lux, _ := d.Lux() - gobottest.Assert(t, lux, 0) + assert.Equal(t, 0, lux) } func TestBH1750Lux(t *testing.T) { @@ -68,13 +68,13 @@ func TestBH1750Lux(t *testing.T) { } lux, _ := d.Lux() - gobottest.Assert(t, lux, 1213) + assert.Equal(t, 1213, lux) } func TestBH1750NullRawSensorData(t *testing.T) { d, _ := initTestBH1750DriverWithStubbedAdaptor() level, _ := d.RawSensorData() - gobottest.Assert(t, level, 0) + assert.Equal(t, 0, level) } func TestBH1750RawSensorData(t *testing.T) { @@ -87,7 +87,7 @@ func TestBH1750RawSensorData(t *testing.T) { } level, _ := d.RawSensorData() - gobottest.Assert(t, level, 1456) + assert.Equal(t, 1456, level) } func TestBH1750LuxError(t *testing.T) { @@ -97,7 +97,7 @@ func TestBH1750LuxError(t *testing.T) { } _, err := d.Lux() - gobottest.Assert(t, err, errors.New("wrong number of bytes read")) + assert.Errorf(t, err, "wrong number of bytes read") } func TestBH1750RawSensorDataError(t *testing.T) { @@ -107,5 +107,5 @@ func TestBH1750RawSensorDataError(t *testing.T) { } _, err := d.RawSensorData() - gobottest.Assert(t, err, errors.New("wrong number of bytes read")) + assert.Errorf(t, err, "wrong number of bytes read") } diff --git a/drivers/i2c/blinkm_driver_test.go b/drivers/i2c/blinkm_driver_test.go index 2093b2b3f..519931a25 100644 --- a/drivers/i2c/blinkm_driver_test.go +++ b/drivers/i2c/blinkm_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,26 +28,26 @@ func TestNewBlinkMDriver(t *testing.T) { if !ok { t.Errorf("NewBlinkMDriver() should have returned a *BlinkMDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BlinkM"), true) - gobottest.Assert(t, d.defaultAddress, 0x09) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BlinkM")) + assert.Equal(t, 0x09, d.defaultAddress) } func TestBlinkMOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewBlinkMDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestBlinkMStart(t *testing.T) { d := NewBlinkMDriver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestBlinkMHalt(t *testing.T) { d, _ := initTestBlinkMDriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } // Commands @@ -55,14 +55,14 @@ func TestNewBlinkMDriverCommands_Rgb(t *testing.T) { d, _ := initTestBlinkMDriverWithStubbedAdaptor() result := d.Command("Rgb")(rgb) - gobottest.Assert(t, result, nil) + assert.Nil(t, result) } func TestNewBlinkMDriverCommands_Fade(t *testing.T) { d, _ := initTestBlinkMDriverWithStubbedAdaptor() result := d.Command("Fade")(rgb) - gobottest.Assert(t, result, nil) + assert.Nil(t, result) } func TestNewBlinkMDriverCommands_FirmwareVersion(t *testing.T) { @@ -77,7 +77,7 @@ func TestNewBlinkMDriverCommands_FirmwareVersion(t *testing.T) { result := d.Command("FirmwareVersion")(param) version, _ := d.FirmwareVersion() - gobottest.Assert(t, result.(map[string]interface{})["version"].(string), version) + assert.Equal(t, version, result.(map[string]interface{})["version"].(string)) // When len(data) is not 2 a.i2cReadImpl = func(b []byte) (int, error) { @@ -87,7 +87,7 @@ func TestNewBlinkMDriverCommands_FirmwareVersion(t *testing.T) { result = d.Command("FirmwareVersion")(param) version, _ = d.FirmwareVersion() - gobottest.Assert(t, result.(map[string]interface{})["version"].(string), version) + assert.Equal(t, version, result.(map[string]interface{})["version"].(string)) } func TestNewBlinkMDriverCommands_Color(t *testing.T) { @@ -97,7 +97,7 @@ func TestNewBlinkMDriverCommands_Color(t *testing.T) { result := d.Command("Color")(param) color, _ := d.Color() - gobottest.Assert(t, result.(map[string]interface{})["color"].([]byte), color) + assert.Equal(t, color, result.(map[string]interface{})["color"].([]byte)) } func TestBlinkMFirmwareVersion(t *testing.T) { @@ -109,7 +109,7 @@ func TestBlinkMFirmwareVersion(t *testing.T) { } version, _ := d.FirmwareVersion() - gobottest.Assert(t, version, "99.1") + assert.Equal(t, "99.1", version) // when len(data) is not 2 a.i2cReadImpl = func(b []byte) (int, error) { @@ -118,14 +118,14 @@ func TestBlinkMFirmwareVersion(t *testing.T) { } version, _ = d.FirmwareVersion() - gobottest.Assert(t, version, "") + assert.Equal(t, "", version) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } _, err := d.FirmwareVersion() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestBlinkMColor(t *testing.T) { @@ -137,7 +137,7 @@ func TestBlinkMColor(t *testing.T) { } color, _ := d.Color() - gobottest.Assert(t, color, []byte{99, 1, 2}) + assert.Equal(t, []byte{99, 1, 2}, color) // when len(data) is not 3 a.i2cReadImpl = func(b []byte) (int, error) { @@ -146,14 +146,14 @@ func TestBlinkMColor(t *testing.T) { } color, _ = d.Color() - gobottest.Assert(t, color, []byte{}) + assert.Equal(t, []byte{}, color) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } _, err := d.Color() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } @@ -164,7 +164,7 @@ func TestBlinkMFade(t *testing.T) { } err := d.Fade(100, 100, 100) - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } @@ -175,6 +175,6 @@ func TestBlinkMRGB(t *testing.T) { } err := d.Rgb(100, 100, 100) - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } diff --git a/drivers/i2c/bme280_driver_test.go b/drivers/i2c/bme280_driver_test.go index 80635ac87..9ffc61313 100644 --- a/drivers/i2c/bme280_driver_test.go +++ b/drivers/i2c/bme280_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -25,15 +25,15 @@ func TestNewBME280Driver(t *testing.T) { if !ok { t.Errorf("NewBME280Driver() should have returned a *BME280Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BMP280"), true) - gobottest.Assert(t, d.defaultAddress, 0x77) - gobottest.Assert(t, d.ctrlPwrMode, uint8(0x03)) - gobottest.Assert(t, d.ctrlPressOversamp, BMP280PressureOversampling(0x05)) - gobottest.Assert(t, d.ctrlTempOversamp, BMP280TemperatureOversampling(0x01)) - gobottest.Assert(t, d.ctrlHumOversamp, BME280HumidityOversampling(0x05)) - gobottest.Assert(t, d.confFilter, BMP280IIRFilter(0x00)) - gobottest.Refute(t, d.calCoeffs, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BMP280")) + assert.Equal(t, 0x77, d.defaultAddress) + assert.Equal(t, uint8(0x03), d.ctrlPwrMode) + assert.Equal(t, BMP280PressureOversampling(0x05), d.ctrlPressOversamp) + assert.Equal(t, BMP280TemperatureOversampling(0x01), d.ctrlTempOversamp) + assert.Equal(t, BME280HumidityOversampling(0x05), d.ctrlHumOversamp) + assert.Equal(t, BMP280IIRFilter(0x00), d.confFilter) + assert.NotNil(t, d.calCoeffs) } func TestBME280Options(t *testing.T) { @@ -44,11 +44,11 @@ func TestBME280Options(t *testing.T) { WithBME280TemperatureOversampling(0x02), WithBME280IIRFilter(0x03), WithBME280HumidityOversampling(0x04)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.ctrlPressOversamp, BMP280PressureOversampling(0x01)) - gobottest.Assert(t, d.ctrlTempOversamp, BMP280TemperatureOversampling(0x02)) - gobottest.Assert(t, d.confFilter, BMP280IIRFilter(0x03)) - gobottest.Assert(t, d.ctrlHumOversamp, BME280HumidityOversampling(0x04)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, BMP280PressureOversampling(0x01), d.ctrlPressOversamp) + assert.Equal(t, BMP280TemperatureOversampling(0x02), d.ctrlTempOversamp) + assert.Equal(t, BMP280IIRFilter(0x03), d.confFilter) + assert.Equal(t, BME280HumidityOversampling(0x04), d.ctrlHumOversamp) } func TestBME280Measurements(t *testing.T) { @@ -72,8 +72,8 @@ func TestBME280Measurements(t *testing.T) { } _ = bme280.Start() hum, err := bme280.Humidity() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, hum, float32(51.20179)) + assert.Nil(t, err) + assert.Equal(t, float32(51.20179), hum) } func TestBME280InitH1Error(t *testing.T) { @@ -92,7 +92,7 @@ func TestBME280InitH1Error(t *testing.T) { return buf.Len(), nil } - gobottest.Assert(t, bme280.Start(), errors.New("h1 read error")) + assert.Errorf(t, bme280.Start(), "h1 read error") } func TestBME280InitH2Error(t *testing.T) { @@ -111,7 +111,7 @@ func TestBME280InitH2Error(t *testing.T) { return buf.Len(), nil } - gobottest.Assert(t, bme280.Start(), errors.New("h2 read error")) + assert.Errorf(t, bme280.Start(), "h2 read error") } func TestBME280HumidityWriteError(t *testing.T) { @@ -122,8 +122,8 @@ func TestBME280HumidityWriteError(t *testing.T) { return 0, errors.New("write error") } hum, err := bme280.Humidity() - gobottest.Assert(t, err, errors.New("write error")) - gobottest.Assert(t, hum, float32(0.0)) + assert.Errorf(t, err, "write error") + assert.Equal(t, float32(0.0), hum) } func TestBME280HumidityReadError(t *testing.T) { @@ -134,8 +134,8 @@ func TestBME280HumidityReadError(t *testing.T) { return 0, errors.New("read error") } hum, err := bme280.Humidity() - gobottest.Assert(t, err, errors.New("read error")) - gobottest.Assert(t, hum, float32(0.0)) + assert.Errorf(t, err, "read error") + assert.Equal(t, float32(0.0), hum) } func TestBME280HumidityNotEnabled(t *testing.T) { @@ -159,8 +159,8 @@ func TestBME280HumidityNotEnabled(t *testing.T) { } _ = bme280.Start() hum, err := bme280.Humidity() - gobottest.Assert(t, err, errors.New("Humidity disabled")) - gobottest.Assert(t, hum, float32(0.0)) + assert.Errorf(t, err, "Humidity disabled") + assert.Equal(t, float32(0.0), hum) } func TestBME280_initializationBME280(t *testing.T) { @@ -186,5 +186,5 @@ func TestBME280_initializationBME280(t *testing.T) { } return 0, nil } - gobottest.Assert(t, bme280.Start(), nil) + assert.Nil(t, bme280.Start()) } diff --git a/drivers/i2c/bmp180_driver_test.go b/drivers/i2c/bmp180_driver_test.go index 87dfcfca6..35056977b 100644 --- a/drivers/i2c/bmp180_driver_test.go +++ b/drivers/i2c/bmp180_driver_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,19 +28,19 @@ func TestNewBMP180Driver(t *testing.T) { if !ok { t.Errorf("NewBMP180Driver() should have returned a *BMP180Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BMP180"), true) - gobottest.Assert(t, d.defaultAddress, 0x77) - gobottest.Assert(t, d.oversampling, BMP180OversamplingMode(0x00)) - gobottest.Refute(t, d.calCoeffs, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BMP180")) + assert.Equal(t, 0x77, d.defaultAddress) + assert.Equal(t, BMP180OversamplingMode(0x00), d.oversampling) + assert.NotNil(t, d.calCoeffs) } func TestBMP180Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewBMP180Driver(newI2cTestAdaptor(), WithBus(2), WithBMP180OversamplingMode(0x01)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.oversampling, BMP180OversamplingMode(0x01)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, BMP180OversamplingMode(0x01), d.oversampling) } func TestBMP180Measurements(t *testing.T) { @@ -72,11 +72,11 @@ func TestBMP180Measurements(t *testing.T) { } _ = bmp180.Start() temp, err := bmp180.Temperature() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, temp, float32(15.0)) + assert.Nil(t, err) + assert.Equal(t, float32(15.0), temp) pressure, err := bmp180.Pressure() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, pressure, float32(69964)) + assert.Nil(t, err) + assert.Equal(t, float32(69964), pressure) } func TestBMP180TemperatureError(t *testing.T) { @@ -108,7 +108,7 @@ func TestBMP180TemperatureError(t *testing.T) { } _ = bmp180.Start() _, err := bmp180.Temperature() - gobottest.Assert(t, err, errors.New("temp error")) + assert.Errorf(t, err, "temp error") } func TestBMP180PressureError(t *testing.T) { @@ -138,7 +138,7 @@ func TestBMP180PressureError(t *testing.T) { } _ = bmp180.Start() _, err := bmp180.Pressure() - gobottest.Assert(t, err, errors.New("press error")) + assert.Errorf(t, err, "press error") } func TestBMP180PressureWriteError(t *testing.T) { @@ -150,7 +150,7 @@ func TestBMP180PressureWriteError(t *testing.T) { } _, err := bmp180.Pressure() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestBMP180_initialization(t *testing.T) { @@ -183,26 +183,26 @@ func TestBMP180_initialization(t *testing.T) { // act, assert - initialization() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0xAA)) - gobottest.Assert(t, d.calCoeffs.ac1, int16(408)) - gobottest.Assert(t, d.calCoeffs.ac2, int16(-72)) - gobottest.Assert(t, d.calCoeffs.ac3, int16(-14383)) - gobottest.Assert(t, d.calCoeffs.ac4, uint16(32741)) - gobottest.Assert(t, d.calCoeffs.ac5, uint16(32757)) - gobottest.Assert(t, d.calCoeffs.ac6, uint16(23153)) - gobottest.Assert(t, d.calCoeffs.b1, int16(6190)) - gobottest.Assert(t, d.calCoeffs.b2, int16(4)) - gobottest.Assert(t, d.calCoeffs.mb, int16(-32768)) - gobottest.Assert(t, d.calCoeffs.mc, int16(-8711)) - gobottest.Assert(t, d.calCoeffs.md, int16(2868)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0xAA), a.written[0]) + assert.Equal(t, int16(408), d.calCoeffs.ac1) + assert.Equal(t, int16(-72), d.calCoeffs.ac2) + assert.Equal(t, int16(-14383), d.calCoeffs.ac3) + assert.Equal(t, uint16(32741), d.calCoeffs.ac4) + assert.Equal(t, uint16(32757), d.calCoeffs.ac5) + assert.Equal(t, uint16(23153), d.calCoeffs.ac6) + assert.Equal(t, int16(6190), d.calCoeffs.b1) + assert.Equal(t, int16(4), d.calCoeffs.b2) + assert.Equal(t, int16(-32768), d.calCoeffs.mb) + assert.Equal(t, int16(-8711), d.calCoeffs.mc) + assert.Equal(t, int16(2868), d.calCoeffs.md) } func TestBMP180_bmp180PauseForReading(t *testing.T) { - gobottest.Assert(t, bmp180PauseForReading(BMP180UltraLowPower), time.Duration(5*time.Millisecond)) - gobottest.Assert(t, bmp180PauseForReading(BMP180Standard), time.Duration(8*time.Millisecond)) - gobottest.Assert(t, bmp180PauseForReading(BMP180HighResolution), time.Duration(14*time.Millisecond)) - gobottest.Assert(t, bmp180PauseForReading(BMP180UltraHighResolution), time.Duration(26*time.Millisecond)) + assert.Equal(t, time.Duration(5*time.Millisecond), bmp180PauseForReading(BMP180UltraLowPower)) + assert.Equal(t, time.Duration(8*time.Millisecond), bmp180PauseForReading(BMP180Standard)) + assert.Equal(t, time.Duration(14*time.Millisecond), bmp180PauseForReading(BMP180HighResolution)) + assert.Equal(t, time.Duration(26*time.Millisecond), bmp180PauseForReading(BMP180UltraHighResolution)) } diff --git a/drivers/i2c/bmp280_driver_test.go b/drivers/i2c/bmp280_driver_test.go index bbbe13c8c..6f769e09f 100644 --- a/drivers/i2c/bmp280_driver_test.go +++ b/drivers/i2c/bmp280_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -25,22 +25,22 @@ func TestNewBMP280Driver(t *testing.T) { if !ok { t.Errorf("NewBMP280Driver() should have returned a *BMP280Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BMP280"), true) - gobottest.Assert(t, d.defaultAddress, 0x77) - gobottest.Assert(t, d.ctrlPwrMode, uint8(0x03)) - gobottest.Assert(t, d.ctrlPressOversamp, BMP280PressureOversampling(0x05)) - gobottest.Assert(t, d.ctrlTempOversamp, BMP280TemperatureOversampling(0x01)) - gobottest.Assert(t, d.confFilter, BMP280IIRFilter(0x00)) - gobottest.Refute(t, d.calCoeffs, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BMP280")) + assert.Equal(t, 0x77, d.defaultAddress) + assert.Equal(t, uint8(0x03), d.ctrlPwrMode) + assert.Equal(t, BMP280PressureOversampling(0x05), d.ctrlPressOversamp) + assert.Equal(t, BMP280TemperatureOversampling(0x01), d.ctrlTempOversamp) + assert.Equal(t, BMP280IIRFilter(0x00), d.confFilter) + assert.NotNil(t, d.calCoeffs) } func TestBMP280Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewBMP280Driver(newI2cTestAdaptor(), WithBus(2), WithBMP280PressureOversampling(0x04)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.ctrlPressOversamp, BMP280PressureOversampling(0x04)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, BMP280PressureOversampling(0x04), d.ctrlPressOversamp) } func TestWithBMP280TemperatureOversampling(t *testing.T) { @@ -53,8 +53,8 @@ func TestWithBMP280TemperatureOversampling(t *testing.T) { // act WithBMP280TemperatureOversampling(setVal)(d) // assert - gobottest.Assert(t, d.ctrlTempOversamp, setVal) - gobottest.Assert(t, len(a.written), 0) + assert.Equal(t, setVal, d.ctrlTempOversamp) + assert.Equal(t, 0, len(a.written)) } func TestWithBMP280IIRFilter(t *testing.T) { @@ -67,8 +67,8 @@ func TestWithBMP280IIRFilter(t *testing.T) { // act WithBMP280IIRFilter(setVal)(d) // assert - gobottest.Assert(t, d.confFilter, setVal) - gobottest.Assert(t, len(a.written), 0) + assert.Equal(t, setVal, d.confFilter) + assert.Equal(t, 0, len(a.written)) } func TestBMP280Measurements(t *testing.T) { @@ -88,14 +88,14 @@ func TestBMP280Measurements(t *testing.T) { } _ = d.Start() temp, err := d.Temperature() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, temp, float32(25.014637)) + assert.Nil(t, err) + assert.Equal(t, float32(25.014637), temp) pressure, err := d.Pressure() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, pressure, float32(99545.414)) + assert.Nil(t, err) + assert.Equal(t, float32(99545.414), pressure) alt, err := d.Altitude() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, alt, float32(149.22713)) + assert.Nil(t, err) + assert.Equal(t, float32(149.22713), alt) } func TestBMP280TemperatureWriteError(t *testing.T) { @@ -106,8 +106,8 @@ func TestBMP280TemperatureWriteError(t *testing.T) { return 0, errors.New("write error") } temp, err := d.Temperature() - gobottest.Assert(t, err, errors.New("write error")) - gobottest.Assert(t, temp, float32(0.0)) + assert.Errorf(t, err, "write error") + assert.Equal(t, float32(0.0), temp) } func TestBMP280TemperatureReadError(t *testing.T) { @@ -118,8 +118,8 @@ func TestBMP280TemperatureReadError(t *testing.T) { return 0, errors.New("read error") } temp, err := d.Temperature() - gobottest.Assert(t, err, errors.New("read error")) - gobottest.Assert(t, temp, float32(0.0)) + assert.Errorf(t, err, "read error") + assert.Equal(t, float32(0.0), temp) } func TestBMP280PressureWriteError(t *testing.T) { @@ -130,8 +130,8 @@ func TestBMP280PressureWriteError(t *testing.T) { return 0, errors.New("write error") } press, err := d.Pressure() - gobottest.Assert(t, err, errors.New("write error")) - gobottest.Assert(t, press, float32(0.0)) + assert.Errorf(t, err, "write error") + assert.Equal(t, float32(0.0), press) } func TestBMP280PressureReadError(t *testing.T) { @@ -142,8 +142,8 @@ func TestBMP280PressureReadError(t *testing.T) { return 0, errors.New("read error") } press, err := d.Pressure() - gobottest.Assert(t, err, errors.New("read error")) - gobottest.Assert(t, press, float32(0.0)) + assert.Errorf(t, err, "read error") + assert.Equal(t, float32(0.0), press) } func TestBMP280_initialization(t *testing.T) { @@ -188,24 +188,24 @@ func TestBMP280_initialization(t *testing.T) { // act, assert - initialization() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 5) - gobottest.Assert(t, a.written[0], wantCalibReg) - gobottest.Assert(t, a.written[1], wantCtrlReg) - gobottest.Assert(t, a.written[2], wantCtrlRegVal) - gobottest.Assert(t, a.written[3], wantConfReg) - gobottest.Assert(t, a.written[4], wantConfRegVal) - gobottest.Assert(t, d.calCoeffs.t1, uint16(27504)) - gobottest.Assert(t, d.calCoeffs.t2, int16(26435)) - gobottest.Assert(t, d.calCoeffs.t3, int16(-1000)) - gobottest.Assert(t, d.calCoeffs.p1, uint16(36477)) - gobottest.Assert(t, d.calCoeffs.p2, int16(-10685)) - gobottest.Assert(t, d.calCoeffs.p3, int16(3024)) - gobottest.Assert(t, d.calCoeffs.p4, int16(2855)) - gobottest.Assert(t, d.calCoeffs.p5, int16(140)) - gobottest.Assert(t, d.calCoeffs.p6, int16(-7)) - gobottest.Assert(t, d.calCoeffs.p7, int16(15500)) - gobottest.Assert(t, d.calCoeffs.p8, int16(-14600)) - gobottest.Assert(t, d.calCoeffs.p9, int16(6000)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 5, len(a.written)) + assert.Equal(t, wantCalibReg, a.written[0]) + assert.Equal(t, wantCtrlReg, a.written[1]) + assert.Equal(t, wantCtrlRegVal, a.written[2]) + assert.Equal(t, wantConfReg, a.written[3]) + assert.Equal(t, wantConfRegVal, a.written[4]) + assert.Equal(t, uint16(27504), d.calCoeffs.t1) + assert.Equal(t, int16(26435), d.calCoeffs.t2) + assert.Equal(t, int16(-1000), d.calCoeffs.t3) + assert.Equal(t, uint16(36477), d.calCoeffs.p1) + assert.Equal(t, int16(-10685), d.calCoeffs.p2) + assert.Equal(t, int16(3024), d.calCoeffs.p3) + assert.Equal(t, int16(2855), d.calCoeffs.p4) + assert.Equal(t, int16(140), d.calCoeffs.p5) + assert.Equal(t, int16(-7), d.calCoeffs.p6) + assert.Equal(t, int16(15500), d.calCoeffs.p7) + assert.Equal(t, int16(-14600), d.calCoeffs.p8) + assert.Equal(t, int16(6000), d.calCoeffs.p9) } diff --git a/drivers/i2c/bmp388_driver_test.go b/drivers/i2c/bmp388_driver_test.go index fb0ce1b59..7f54414f5 100644 --- a/drivers/i2c/bmp388_driver_test.go +++ b/drivers/i2c/bmp388_driver_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -44,20 +44,20 @@ func TestNewBMP388Driver(t *testing.T) { if !ok { t.Errorf("NewBMP388Driver() should have returned a *BMP388Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BMP388"), true) - gobottest.Assert(t, d.defaultAddress, 0x77) - gobottest.Assert(t, d.ctrlPwrMode, uint8(0x01)) // forced mode - gobottest.Assert(t, d.confFilter, BMP388IIRFilter(0x00)) // filter off - gobottest.Refute(t, d.calCoeffs, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "BMP388")) + assert.Equal(t, 0x77, d.defaultAddress) + assert.Equal(t, uint8(0x01), d.ctrlPwrMode) // forced mode + assert.Equal(t, BMP388IIRFilter(0x00), d.confFilter) // filter off + assert.NotNil(t, d.calCoeffs) } func TestBMP388Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewBMP388Driver(newI2cTestAdaptor(), WithBus(2), WithBMP388IIRFilter(BMP388IIRFilter(0x03))) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.confFilter, BMP388IIRFilter(0x03)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, BMP388IIRFilter(0x03), d.confFilter) } func TestBMP388Measurements(t *testing.T) { @@ -84,14 +84,14 @@ func TestBMP388Measurements(t *testing.T) { } _ = d.Start() temp, err := d.Temperature(2) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, temp, float32(22.906143)) + assert.Nil(t, err) + assert.Equal(t, float32(22.906143), temp) pressure, err := d.Pressure(2) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, pressure, float32(98874.85)) + assert.Nil(t, err) + assert.Equal(t, float32(98874.85), pressure) alt, err := d.Altitude(2) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, alt, float32(205.89395)) + assert.Nil(t, err) + assert.Equal(t, float32(205.89395), alt) } func TestBMP388TemperatureWriteError(t *testing.T) { @@ -102,8 +102,8 @@ func TestBMP388TemperatureWriteError(t *testing.T) { return 0, errors.New("write error") } temp, err := d.Temperature(2) - gobottest.Assert(t, err, errors.New("write error")) - gobottest.Assert(t, temp, float32(0.0)) + assert.Errorf(t, err, "write error") + assert.Equal(t, float32(0.0), temp) } func TestBMP388TemperatureReadError(t *testing.T) { @@ -114,8 +114,8 @@ func TestBMP388TemperatureReadError(t *testing.T) { return 0, errors.New("read error") } temp, err := d.Temperature(2) - gobottest.Assert(t, err, errors.New("read error")) - gobottest.Assert(t, temp, float32(0.0)) + assert.Errorf(t, err, "read error") + assert.Equal(t, float32(0.0), temp) } func TestBMP388PressureWriteError(t *testing.T) { @@ -126,8 +126,8 @@ func TestBMP388PressureWriteError(t *testing.T) { return 0, errors.New("write error") } press, err := d.Pressure(2) - gobottest.Assert(t, err, errors.New("write error")) - gobottest.Assert(t, press, float32(0.0)) + assert.Errorf(t, err, "write error") + assert.Equal(t, float32(0.0), press) } func TestBMP388PressureReadError(t *testing.T) { @@ -138,8 +138,8 @@ func TestBMP388PressureReadError(t *testing.T) { return 0, errors.New("read error") } press, err := d.Pressure(2) - gobottest.Assert(t, err, errors.New("read error")) - gobottest.Assert(t, press, float32(0.0)) + assert.Errorf(t, err, "read error") + assert.Equal(t, float32(0.0), press) } func TestBMP388_initialization(t *testing.T) { @@ -176,25 +176,25 @@ func TestBMP388_initialization(t *testing.T) { // act, assert - initialization() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], wantChipIDReg) - gobottest.Assert(t, a.written[1], wantCalibReg) - gobottest.Assert(t, a.written[2], wantCommandReg) - gobottest.Assert(t, a.written[3], wantCommandRegVal) - gobottest.Assert(t, a.written[4], wantConfReg) - gobottest.Assert(t, a.written[5], wantConfRegVal) - gobottest.Assert(t, d.calCoeffs.t1, float32(7.021568e+06)) - gobottest.Assert(t, d.calCoeffs.t2, float32(1.7549843e-05)) - gobottest.Assert(t, d.calCoeffs.t3, float32(-3.5527137e-14)) - gobottest.Assert(t, d.calCoeffs.p1, float32(-0.015769958)) - gobottest.Assert(t, d.calCoeffs.p2, float32(-3.5410747e-05)) - gobottest.Assert(t, d.calCoeffs.p3, float32(8.1490725e-09)) - gobottest.Assert(t, d.calCoeffs.p4, float32(0)) - gobottest.Assert(t, d.calCoeffs.p5, float32(208056)) - gobottest.Assert(t, d.calCoeffs.p6, float32(490.875)) - gobottest.Assert(t, d.calCoeffs.p7, float32(-0.05078125)) - gobottest.Assert(t, d.calCoeffs.p8, float32(-0.00030517578)) - gobottest.Assert(t, d.calCoeffs.p9, float32(5.8957283e-11)) + assert.Nil(t, err) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, wantChipIDReg, a.written[0]) + assert.Equal(t, wantCalibReg, a.written[1]) + assert.Equal(t, wantCommandReg, a.written[2]) + assert.Equal(t, wantCommandRegVal, a.written[3]) + assert.Equal(t, wantConfReg, a.written[4]) + assert.Equal(t, wantConfRegVal, a.written[5]) + assert.Equal(t, float32(7.021568e+06), d.calCoeffs.t1) + assert.Equal(t, float32(1.7549843e-05), d.calCoeffs.t2) + assert.Equal(t, float32(-3.5527137e-14), d.calCoeffs.t3) + assert.Equal(t, float32(-0.015769958), d.calCoeffs.p1) + assert.Equal(t, float32(-3.5410747e-05), d.calCoeffs.p2) + assert.Equal(t, float32(8.1490725e-09), d.calCoeffs.p3) + assert.Equal(t, float32(0), d.calCoeffs.p4) + assert.Equal(t, float32(208056), d.calCoeffs.p5) + assert.Equal(t, float32(490.875), d.calCoeffs.p6) + assert.Equal(t, float32(-0.05078125), d.calCoeffs.p7) + assert.Equal(t, float32(-0.00030517578), d.calCoeffs.p8) + assert.Equal(t, float32(5.8957283e-11), d.calCoeffs.p9) } diff --git a/drivers/i2c/ccs811_driver_test.go b/drivers/i2c/ccs811_driver_test.go index 56f01cfe6..956821443 100644 --- a/drivers/i2c/ccs811_driver_test.go +++ b/drivers/i2c/ccs811_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -24,25 +24,25 @@ func TestNewCCS811Driver(t *testing.T) { if !ok { t.Errorf("NewCCS811Driver() should have returned a *CCS811Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "CCS811"), true) - gobottest.Assert(t, d.defaultAddress, 0x5A) - gobottest.Refute(t, d.measMode, nil) - gobottest.Assert(t, d.ntcResistanceValue, uint32(100000)) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "CCS811")) + assert.Equal(t, 0x5A, d.defaultAddress) + assert.NotNil(t, d.measMode) + assert.Equal(t, uint32(100000), d.ntcResistanceValue) } func TestCCS811Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewCCS811Driver(newI2cTestAdaptor(), WithBus(2), WithAddress(0xFF), WithCCS811NTCResistance(0xFF)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.GetAddressOrDefault(0x5a), 0xFF) - gobottest.Assert(t, d.ntcResistanceValue, uint32(0xFF)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, 0xFF, d.GetAddressOrDefault(0x5a)) + assert.Equal(t, uint32(0xFF), d.ntcResistanceValue) } func TestCCS811WithCCS811MeasMode(t *testing.T) { d := NewCCS811Driver(newI2cTestAdaptor(), WithCCS811MeasMode(CCS811DriveMode10Sec)) - gobottest.Assert(t, d.measMode.driveMode, CCS811DriveMode(CCS811DriveMode10Sec)) + assert.Equal(t, CCS811DriveMode(CCS811DriveMode10Sec), d.measMode.driveMode) } func TestCCS811GetGasData(t *testing.T) { @@ -91,9 +91,9 @@ func TestCCS811GetGasData(t *testing.T) { // act eco2, tvoc, err := d.GetGasData() // assert - gobottest.Assert(t, eco2, tc.eco2) - gobottest.Assert(t, tvoc, tc.tvoc) - gobottest.Assert(t, err, tc.err) + assert.Equal(t, tc.eco2, eco2) + assert.Equal(t, tc.tvoc, tvoc) + assert.Equal(t, tc.err, err) }) } } @@ -148,8 +148,8 @@ func TestCCS811GetTemperature(t *testing.T) { // act temp, err := d.GetTemperature() // assert - gobottest.Assert(t, temp, tc.temp) - gobottest.Assert(t, err, tc.err) + assert.Equal(t, tc.temp, temp) + assert.Equal(t, tc.err, err) }) } } @@ -212,8 +212,8 @@ func TestCCS811HasData(t *testing.T) { // act result, err := d.HasData() // assert - gobottest.Assert(t, result, tc.result) - gobottest.Assert(t, err, tc.err) + assert.Equal(t, tc.result, result) + assert.Equal(t, tc.err, err) }) } } @@ -255,13 +255,13 @@ func TestCCS811_initialize(t *testing.T) { // arrange, act - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 9) - gobottest.Assert(t, a.written[0], wantChipIDReg) - gobottest.Assert(t, a.written[1], wantResetReg) - gobottest.Assert(t, a.written[2:6], wantResetRegSequence) - gobottest.Assert(t, a.written[6], wantAppStartReg) - gobottest.Assert(t, a.written[7], wantMeasReg) - gobottest.Assert(t, a.written[8], wantMeasRegVal) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 9, len(a.written)) + assert.Equal(t, wantChipIDReg, a.written[0]) + assert.Equal(t, wantResetReg, a.written[1]) + assert.Equal(t, wantResetRegSequence, a.written[2:6]) + assert.Equal(t, wantAppStartReg, a.written[6]) + assert.Equal(t, wantMeasReg, a.written[7]) + assert.Equal(t, wantMeasRegVal, a.written[8]) } diff --git a/drivers/i2c/drv2605l_driver_test.go b/drivers/i2c/drv2605l_driver_test.go index 7fd988847..125a0f9c5 100644 --- a/drivers/i2c/drv2605l_driver_test.go +++ b/drivers/i2c/drv2605l_driver_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -37,21 +37,21 @@ func TestNewDRV2605LDriver(t *testing.T) { if !ok { t.Errorf("NewDRV2605LDriver() should have returned a *DRV2605LDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "DRV2605L"), true) - gobottest.Assert(t, d.defaultAddress, 0x5a) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "DRV2605L")) + assert.Equal(t, 0x5a, d.defaultAddress) } func TestDRV2605LOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewDRV2605LDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestDRV2605LStart(t *testing.T) { d := NewDRV2605LDriver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestDRV2605LHalt(t *testing.T) { @@ -62,33 +62,33 @@ func TestDRV2605LHalt(t *testing.T) { writeNewStandbyModeData := []byte{drv2605RegMode, 42 | drv2605Standby} d, a := initTestDRV2605LDriverWithStubbedAdaptor() a.written = []byte{} - gobottest.Assert(t, d.Halt(), nil) - gobottest.Assert(t, a.written, append(append(writeStopPlaybackData, readCurrentStandbyModeData), writeNewStandbyModeData...)) + assert.Nil(t, d.Halt()) + assert.Equal(t, append(append(writeStopPlaybackData, readCurrentStandbyModeData), writeNewStandbyModeData...), a.written) } func TestDRV2605LGetPause(t *testing.T) { d, _ := initTestDRV2605LDriverWithStubbedAdaptor() - gobottest.Assert(t, d.GetPauseWaveform(0), uint8(0x80)) - gobottest.Assert(t, d.GetPauseWaveform(1), uint8(0x81)) - gobottest.Assert(t, d.GetPauseWaveform(128), d.GetPauseWaveform(127)) + assert.Equal(t, uint8(0x80), d.GetPauseWaveform(0)) + assert.Equal(t, uint8(0x81), d.GetPauseWaveform(1)) + assert.Equal(t, d.GetPauseWaveform(127), d.GetPauseWaveform(128)) } func TestDRV2605LSequenceTermination(t *testing.T) { d, a := initTestDRV2605LDriverWithStubbedAdaptor() a.written = []byte{} - gobottest.Assert(t, d.SetSequence([]byte{1, 2}), nil) - gobottest.Assert(t, a.written, []byte{ + assert.Nil(t, d.SetSequence([]byte{1, 2})) + assert.Equal(t, []byte{ drv2605RegWaveSeq1, 1, drv2605RegWaveSeq2, 2, drv2605RegWaveSeq3, 0, - }) + }, a.written) } func TestDRV2605LSequenceTruncation(t *testing.T) { d, a := initTestDRV2605LDriverWithStubbedAdaptor() a.written = []byte{} - gobottest.Assert(t, d.SetSequence([]byte{1, 2, 3, 4, 5, 6, 7, 8, 99, 100}), nil) - gobottest.Assert(t, a.written, []byte{ + assert.Nil(t, d.SetSequence([]byte{1, 2, 3, 4, 5, 6, 7, 8, 99, 100})) + assert.Equal(t, []byte{ drv2605RegWaveSeq1, 1, drv2605RegWaveSeq2, 2, drv2605RegWaveSeq3, 3, @@ -97,12 +97,12 @@ func TestDRV2605LSequenceTruncation(t *testing.T) { drv2605RegWaveSeq6, 6, drv2605RegWaveSeq7, 7, drv2605RegWaveSeq8, 8, - }) + }, a.written) } func TestDRV2605LSetMode(t *testing.T) { d, _ := initTestDRV2605LDriverWithStubbedAdaptor() - gobottest.Assert(t, d.SetMode(DRV2605ModeIntTrig), nil) + assert.Nil(t, d.SetMode(DRV2605ModeIntTrig)) } func TestDRV2605LSetModeReadError(t *testing.T) { @@ -110,12 +110,12 @@ func TestDRV2605LSetModeReadError(t *testing.T) { a.i2cReadImpl = func(b []byte) (int, error) { return 0, errors.New("read error") } - gobottest.Assert(t, d.SetMode(DRV2605ModeIntTrig), errors.New("read error")) + assert.Errorf(t, d.SetMode(DRV2605ModeIntTrig), "read error") } func TestDRV2605LSetStandbyMode(t *testing.T) { d, _ := initTestDRV2605LDriverWithStubbedAdaptor() - gobottest.Assert(t, d.SetStandbyMode(true), nil) + assert.Nil(t, d.SetStandbyMode(true)) } func TestDRV2605LSetStandbyModeReadError(t *testing.T) { @@ -123,15 +123,15 @@ func TestDRV2605LSetStandbyModeReadError(t *testing.T) { a.i2cReadImpl = func(b []byte) (int, error) { return 0, errors.New("read error") } - gobottest.Assert(t, d.SetStandbyMode(true), errors.New("read error")) + assert.Errorf(t, d.SetStandbyMode(true), "read error") } func TestDRV2605LSelectLibrary(t *testing.T) { d, _ := initTestDRV2605LDriverWithStubbedAdaptor() - gobottest.Assert(t, d.SelectLibrary(1), nil) + assert.Nil(t, d.SelectLibrary(1)) } func TestDRV2605LGo(t *testing.T) { d, _ := initTestDRV2605LDriverWithStubbedAdaptor() - gobottest.Assert(t, d.Go(), nil) + assert.Nil(t, d.Go()) } diff --git a/drivers/i2c/generic_driver_test.go b/drivers/i2c/generic_driver_test.go index 44d6d94d6..fdb490e69 100644 --- a/drivers/i2c/generic_driver_test.go +++ b/drivers/i2c/generic_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*GenericDriver)(nil) @@ -20,6 +20,6 @@ func TestNewGenericDriver(t *testing.T) { if !ok { t.Errorf("NewGenericDriver() should have returned a *GenericDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "GenericI2C"), true) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "GenericI2C")) } diff --git a/drivers/i2c/grove_drivers_test.go b/drivers/i2c/grove_drivers_test.go index 2d94f7711..eff163972 100644 --- a/drivers/i2c/grove_drivers_test.go +++ b/drivers/i2c/grove_drivers_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*GroveLcdDriver)(nil) @@ -33,24 +33,24 @@ func initGroveAccelerometerDriverWithStubbedAdaptor() (*GroveAccelerometerDriver func TestGroveLcdDriverName(t *testing.T) { g := initTestGroveLcdDriver() - gobottest.Refute(t, g.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(g.Name(), "JHD1313M1"), true) + assert.NotNil(t, g.Connection()) + assert.True(t, strings.HasPrefix(g.Name(), "JHD1313M1")) } func TestLcdDriverWithAddress(t *testing.T) { adaptor := newI2cTestAdaptor() g := NewGroveLcdDriver(adaptor, WithAddress(0x66)) - gobottest.Assert(t, g.GetAddressOrDefault(0x33), 0x66) + assert.Equal(t, 0x66, g.GetAddressOrDefault(0x33)) } func TestGroveAccelerometerDriverName(t *testing.T) { g := initTestGroveAccelerometerDriver() - gobottest.Refute(t, g.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(g.Name(), "MMA7660"), true) + assert.NotNil(t, g.Connection()) + assert.True(t, strings.HasPrefix(g.Name(), "MMA7660")) } func TestGroveAccelerometerDriverWithAddress(t *testing.T) { adaptor := newI2cTestAdaptor() g := NewGroveAccelerometerDriver(adaptor, WithAddress(0x66)) - gobottest.Assert(t, g.GetAddressOrDefault(0x33), 0x66) + assert.Equal(t, 0x66, g.GetAddressOrDefault(0x33)) } diff --git a/drivers/i2c/grovepi_driver_test.go b/drivers/i2c/grovepi_driver_test.go index dad364537..23b16db5f 100644 --- a/drivers/i2c/grovepi_driver_test.go +++ b/drivers/i2c/grovepi_driver_test.go @@ -5,10 +5,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/aio" "gobot.io/x/gobot/v2/drivers/gpio" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -41,17 +41,17 @@ func TestNewGrovePiDriver(t *testing.T) { if !ok { t.Errorf("NewGrovePiDriver() should have returned a *GrovePiDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "GrovePi"), true) - gobottest.Assert(t, d.defaultAddress, 0x04) - gobottest.Refute(t, d.pins, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "GrovePi")) + assert.Equal(t, 0x04, d.defaultAddress) + assert.NotNil(t, d.pins) } func TestGrovePiOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewGrovePiDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestGrovePiSomeRead(t *testing.T) { @@ -166,13 +166,13 @@ func TestGrovePiSomeRead(t *testing.T) { return } // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, a.written, tc.wantWritten) - gobottest.Assert(t, numCallsRead, len(tc.simResponse)) - gobottest.Assert(t, got, tc.wantResult) - gobottest.Assert(t, gotF1, tc.wantResultF1) - gobottest.Assert(t, gotF2, tc.wantResultF2) - gobottest.Assert(t, gotString, tc.wantResultString) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantWritten, a.written) + assert.Equal(t, len(tc.simResponse), numCallsRead) + assert.Equal(t, tc.wantResult, got) + assert.Equal(t, tc.wantResultF1, gotF1) + assert.Equal(t, tc.wantResultF2, gotF2) + assert.Equal(t, tc.wantResultString, gotString) }) } } @@ -219,16 +219,16 @@ func TestGrovePiSomeWrite(t *testing.T) { return } // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Nil(t, err) + assert.Equal(t, tc.wantWritten, a.written) }) } } func TestGrovePi_getPin(t *testing.T) { - gobottest.Assert(t, getPin("a1"), "1") - gobottest.Assert(t, getPin("A16"), "16") - gobottest.Assert(t, getPin("D3"), "3") - gobottest.Assert(t, getPin("d22"), "22") - gobottest.Assert(t, getPin("22"), "22") + assert.Equal(t, "1", getPin("a1")) + assert.Equal(t, "16", getPin("A16")) + assert.Equal(t, "3", getPin("D3")) + assert.Equal(t, "22", getPin("d22")) + assert.Equal(t, "22", getPin("22")) } diff --git a/drivers/i2c/hmc5883l_driver_test.go b/drivers/i2c/hmc5883l_driver_test.go index a7a88d9b0..c7b9b2dff 100644 --- a/drivers/i2c/hmc5883l_driver_test.go +++ b/drivers/i2c/hmc5883l_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -23,40 +23,40 @@ func TestNewHMC5883LDriver(t *testing.T) { if !ok { t.Errorf("NewHMC5883LDriver() should have returned a *HMC5883LDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.name, "HMC5883L"), true) - gobottest.Assert(t, d.defaultAddress, 0x1E) - gobottest.Assert(t, d.samplesAvg, uint8(8)) - gobottest.Assert(t, d.outputRate, uint32(15000)) - gobottest.Assert(t, d.applyBias, int8(0)) - gobottest.Assert(t, d.measurementMode, 0) - gobottest.Assert(t, d.gain, 390.0) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.name, "HMC5883L")) + assert.Equal(t, 0x1E, d.defaultAddress) + assert.Equal(t, uint8(8), d.samplesAvg) + assert.Equal(t, uint32(15000), d.outputRate) + assert.Equal(t, int8(0), d.applyBias) + assert.Equal(t, 0, d.measurementMode) + assert.Equal(t, 390.0, d.gain) } func TestHMC5883LOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewHMC5883LDriver(newI2cTestAdaptor(), WithBus(2), WithHMC5883LSamplesAveraged(4)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.samplesAvg, uint8(4)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, uint8(4), d.samplesAvg) } func TestHMC5883LWithHMC5883LDataOutputRate(t *testing.T) { d := NewHMC5883LDriver(newI2cTestAdaptor()) WithHMC5883LDataOutputRate(7500)(d) - gobottest.Assert(t, d.outputRate, uint32(7500)) + assert.Equal(t, uint32(7500), d.outputRate) } func TestHMC5883LWithHMC5883LApplyBias(t *testing.T) { d := NewHMC5883LDriver(newI2cTestAdaptor()) WithHMC5883LApplyBias(-1)(d) - gobottest.Assert(t, d.applyBias, int8(-1)) + assert.Equal(t, int8(-1), d.applyBias) } func TestHMC5883LWithHMC5883LGain(t *testing.T) { d := NewHMC5883LDriver(newI2cTestAdaptor()) WithHMC5883LGain(230)(d) - gobottest.Assert(t, d.gain, 230.0) + assert.Equal(t, 230.0, d.gain) } func TestHMC5883LRead(t *testing.T) { @@ -121,10 +121,10 @@ func TestHMC5883LRead(t *testing.T) { // act gotX, gotY, gotZ, err := d.Read() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, gotX, tc.wantX) - gobottest.Assert(t, gotY, tc.wantY) - gobottest.Assert(t, gotZ, tc.wantZ) + assert.Nil(t, err) + assert.Equal(t, tc.wantX, gotX) + assert.Equal(t, tc.wantY, gotY) + assert.Equal(t, tc.wantZ, gotZ) }) } } @@ -177,13 +177,13 @@ func TestHMC5883L_readRawData(t *testing.T) { // act gotX, gotY, gotZ, err := d.readRawData() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, gotX, tc.wantX) - gobottest.Assert(t, gotY, tc.wantY) - gobottest.Assert(t, gotZ, tc.wantZ) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(hmc5883lAxisX)) + assert.Nil(t, err) + assert.Equal(t, tc.wantX, gotX) + assert.Equal(t, tc.wantY, gotY) + assert.Equal(t, tc.wantZ, gotZ) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(hmc5883lAxisX), a.written[0]) }) } } @@ -203,12 +203,12 @@ func TestHMC5883L_initialize(t *testing.T) { // act, assert - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], uint8(hmc5883lRegA)) - gobottest.Assert(t, a.written[1], wantRegA) - gobottest.Assert(t, a.written[2], uint8(hmc5883lRegB)) - gobottest.Assert(t, a.written[3], wantRegB) - gobottest.Assert(t, a.written[4], uint8(hmc5883lRegMode)) - gobottest.Assert(t, a.written[5], wantRegM) + assert.Nil(t, err) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, uint8(hmc5883lRegA), a.written[0]) + assert.Equal(t, wantRegA, a.written[1]) + assert.Equal(t, uint8(hmc5883lRegB), a.written[2]) + assert.Equal(t, wantRegB, a.written[3]) + assert.Equal(t, uint8(hmc5883lRegMode), a.written[4]) + assert.Equal(t, wantRegM, a.written[5]) } diff --git a/drivers/i2c/hmc6352_driver_test.go b/drivers/i2c/hmc6352_driver_test.go index fa2e01c0f..81fcd14df 100644 --- a/drivers/i2c/hmc6352_driver_test.go +++ b/drivers/i2c/hmc6352_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,26 +28,26 @@ func TestNewHMC6352Driver(t *testing.T) { if !ok { t.Errorf("NewHMC6352Driver() should have returned a *HMC6352Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "HMC6352"), true) - gobottest.Assert(t, d.defaultAddress, 0x21) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "HMC6352")) + assert.Equal(t, 0x21, d.defaultAddress) } func TestHMC6352Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewHMC6352Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestHMC6352Start(t *testing.T) { d := NewHMC6352Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestHMC6352Halt(t *testing.T) { d, _ := initTestHMC6352DriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestHMC6352Heading(t *testing.T) { @@ -59,7 +59,7 @@ func TestHMC6352Heading(t *testing.T) { } heading, _ := d.Heading() - gobottest.Assert(t, heading, uint16(2534)) + assert.Equal(t, uint16(2534), heading) // when len(data) is not 2 d, a = initTestHMC6352DriverWithStubbedAdaptor() @@ -69,8 +69,8 @@ func TestHMC6352Heading(t *testing.T) { } heading, err := d.Heading() - gobottest.Assert(t, heading, uint16(0)) - gobottest.Assert(t, err, ErrNotEnoughBytes) + assert.Equal(t, uint16(0), heading) + assert.Equal(t, ErrNotEnoughBytes, err) // when read error d, a = initTestHMC6352DriverWithStubbedAdaptor() @@ -79,8 +79,8 @@ func TestHMC6352Heading(t *testing.T) { } heading, err = d.Heading() - gobottest.Assert(t, heading, uint16(0)) - gobottest.Assert(t, err, errors.New("read error")) + assert.Equal(t, uint16(0), heading) + assert.Errorf(t, err, "read error") // when write error d, a = initTestHMC6352DriverWithStubbedAdaptor() @@ -89,6 +89,6 @@ func TestHMC6352Heading(t *testing.T) { } heading, err = d.Heading() - gobottest.Assert(t, heading, uint16(0)) - gobottest.Assert(t, err, errors.New("write error")) + assert.Equal(t, uint16(0), heading) + assert.Errorf(t, err, "write error") } diff --git a/drivers/i2c/i2c_config_test.go b/drivers/i2c/i2c_config_test.go index fac9087ae..522e506bb 100644 --- a/drivers/i2c/i2c_config_test.go +++ b/drivers/i2c/i2c_config_test.go @@ -3,7 +3,7 @@ package i2c import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestNewConfig(t *testing.T) { @@ -14,8 +14,8 @@ func TestNewConfig(t *testing.T) { if !ok { t.Errorf("NewConfig() should have returned a *i2cConfig") } - gobottest.Assert(t, c.bus, BusNotInitialized) - gobottest.Assert(t, c.address, AddressNotInitialized) + assert.Equal(t, BusNotInitialized, c.bus) + assert.Equal(t, AddressNotInitialized, c.address) } func TestWithBus(t *testing.T) { @@ -24,7 +24,7 @@ func TestWithBus(t *testing.T) { // act c.SetBus(0x23) // assert - gobottest.Assert(t, c.(*i2cConfig).bus, 0x23) + assert.Equal(t, 0x23, c.(*i2cConfig).bus) } func TestWithAddress(t *testing.T) { @@ -33,7 +33,7 @@ func TestWithAddress(t *testing.T) { // act c.SetAddress(0x24) // assert - gobottest.Assert(t, c.(*i2cConfig).address, 0x24) + assert.Equal(t, 0x24, c.(*i2cConfig).address) } func TestGetBusOrDefaultWithBusOption(t *testing.T) { @@ -53,7 +53,7 @@ func TestGetBusOrDefaultWithBusOption(t *testing.T) { WithBus(tc.init)(c) got := c.GetBusOrDefault(tc.bus) // assert - gobottest.Assert(t, got, tc.want) + assert.Equal(t, tc.want, got) }) } } @@ -75,7 +75,7 @@ func TestGetAddressOrDefaultWithAddressOption(t *testing.T) { WithAddress(tc.init)(c) got := c.GetAddressOrDefault(tc.address) // assert - gobottest.Assert(t, got, tc.want) + assert.Equal(t, tc.want, got) }) } } diff --git a/drivers/i2c/i2c_connection_test.go b/drivers/i2c/i2c_connection_test.go index 7e7600742..a243dd013 100644 --- a/drivers/i2c/i2c_connection_test.go +++ b/drivers/i2c/i2c_connection_test.go @@ -4,13 +4,12 @@ package i2c import ( - "errors" "testing" "unsafe" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -72,130 +71,130 @@ func initI2CDeviceAddressError() gobot.I2cSystemDevicer { func TestI2CAddress(t *testing.T) { c := NewConnection(initI2CDevice(), 0x66) - gobottest.Assert(t, c.address, 0x66) + assert.Equal(t, 0x66, c.address) } func TestI2CClose(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) - gobottest.Assert(t, c.Close(), nil) + assert.Nil(t, c.Close()) } func TestI2CRead(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) i, _ := c.Read([]byte{}) - gobottest.Assert(t, i, 0) + assert.Equal(t, 0, i) } func TestI2CReadAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) _, err := c.Read([]byte{}) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CWrite(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) i, _ := c.Write([]byte{0x01}) - gobottest.Assert(t, i, 1) + assert.Equal(t, 1, i) } func TestI2CWriteAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) _, err := c.Write([]byte{0x01}) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CReadByte(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) v, _ := c.ReadByte() - gobottest.Assert(t, v, uint8(0xFC)) + assert.Equal(t, uint8(0xFC), v) } func TestI2CReadByteAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) _, err := c.ReadByte() - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CReadByteData(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) v, _ := c.ReadByteData(0x01) - gobottest.Assert(t, v, uint8(0xFD)) + assert.Equal(t, uint8(0xFD), v) } func TestI2CReadByteDataAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) _, err := c.ReadByteData(0x01) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CReadWordData(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) v, _ := c.ReadWordData(0x01) - gobottest.Assert(t, v, uint16(0xFFFE)) + assert.Equal(t, uint16(0xFFFE), v) } func TestI2CReadWordDataAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) _, err := c.ReadWordData(0x01) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CWriteByte(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) err := c.WriteByte(0x01) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestI2CWriteByteAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) err := c.WriteByte(0x01) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CWriteByteData(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) err := c.WriteByteData(0x01, 0x01) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestI2CWriteByteDataAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) err := c.WriteByteData(0x01, 0x01) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CWriteWordData(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) err := c.WriteWordData(0x01, 0x01) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestI2CWriteWordDataAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) err := c.WriteWordData(0x01, 0x01) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func TestI2CWriteBlockData(t *testing.T) { c := NewConnection(initI2CDevice(), 0x06) err := c.WriteBlockData(0x01, []byte{0x01, 0x02}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestI2CWriteBlockDataAddressError(t *testing.T) { c := NewConnection(initI2CDeviceAddressError(), 0x06) err := c.WriteBlockData(0x01, []byte{0x01, 0x02}) - gobottest.Assert(t, err, errors.New("Setting address failed with syscall.Errno operation not permitted")) + assert.Errorf(t, err, "Setting address failed with syscall.Errno operation not permitted") } func Test_setBit(t *testing.T) { var expectedVal uint8 = 129 actualVal := setBit(1, 7) - gobottest.Assert(t, expectedVal, actualVal) + assert.Equal(t, actualVal, expectedVal) } func Test_clearBit(t *testing.T) { var expectedVal uint8 actualVal := clearBit(128, 7) - gobottest.Assert(t, expectedVal, actualVal) + assert.Equal(t, actualVal, expectedVal) } diff --git a/drivers/i2c/i2c_driver_test.go b/drivers/i2c/i2c_driver_test.go index 3fed2a785..51bc13e57 100644 --- a/drivers/i2c/i2c_driver_test.go +++ b/drivers/i2c/i2c_driver_test.go @@ -1,12 +1,10 @@ package i2c import ( - "errors" - "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -32,15 +30,15 @@ func TestNewDriver(t *testing.T) { if !ok { t.Errorf("NewDriver() should have returned a *Driver") } - gobottest.Assert(t, strings.Contains(d.name, "I2C_BASIC"), true) - gobottest.Assert(t, d.defaultAddress, 0x15) - gobottest.Assert(t, d.connector, a) - gobottest.Assert(t, d.connection, nil) - gobottest.Assert(t, d.afterStart(), nil) - gobottest.Assert(t, d.beforeHalt(), nil) - gobottest.Refute(t, d.Config, nil) - gobottest.Refute(t, d.Commander, nil) - gobottest.Refute(t, d.mutex, nil) + assert.Contains(t, d.name, "I2C_BASIC") + assert.Equal(t, 0x15, d.defaultAddress) + assert.Equal(t, a, d.connector) + assert.Nil(t, d.connection) + assert.Nil(t, d.afterStart()) + assert.Nil(t, d.beforeHalt()) + assert.NotNil(t, d.Config) + assert.NotNil(t, d.Commander) + assert.NotNil(t, d.mutex) } func TestSetName(t *testing.T) { @@ -49,22 +47,22 @@ func TestSetName(t *testing.T) { // act d.SetName("TESTME") // assert - gobottest.Assert(t, d.Name(), "TESTME") + assert.Equal(t, "TESTME", d.Name()) } func TestConnection(t *testing.T) { // arrange d := initTestDriver() // act, assert - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) } func TestStart(t *testing.T) { // arrange d, a := initDriverWithStubbedAdaptor() // act, assert - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, 0x15, a.address) + assert.Nil(t, d.Start()) + assert.Equal(t, a.address, 0x15) } func TestStartConnectError(t *testing.T) { @@ -72,14 +70,14 @@ func TestStartConnectError(t *testing.T) { d, a := initDriverWithStubbedAdaptor() a.Testi2cConnectErr(true) // act, assert - gobottest.Assert(t, d.Start(), errors.New("Invalid i2c connection")) + assert.Errorf(t, d.Start(), "Invalid i2c connection") } func TestHalt(t *testing.T) { // arrange d := initTestDriver() // act, assert - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestWrite(t *testing.T) { @@ -100,10 +98,10 @@ func TestWrite(t *testing.T) { // act err := d.Write(address, value) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, a.written[0], wantAddress) - gobottest.Assert(t, a.written[1], uint8(value)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, wantAddress, a.written[0]) + assert.Equal(t, uint8(value), a.written[1]) } func TestRead(t *testing.T) { @@ -131,9 +129,9 @@ func TestRead(t *testing.T) { // act val, err := d.Read(address) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, val, int(want)) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, a.written[0], wantAddress) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, int(want), val) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, wantAddress, a.written[0]) + assert.Equal(t, 1, numCallsRead) } diff --git a/drivers/i2c/ina3221_driver_test.go b/drivers/i2c/ina3221_driver_test.go index 3564fd824..2e490830e 100644 --- a/drivers/i2c/ina3221_driver_test.go +++ b/drivers/i2c/ina3221_driver_test.go @@ -7,8 +7,8 @@ import ( "strings" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -30,26 +30,26 @@ func TestNewINA3221Driver(t *testing.T) { if !ok { t.Error("NewINA3221Driver() should return a *INA3221Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "INA3221"), true) - gobottest.Assert(t, d.defaultAddress, 0x40) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "INA3221")) + assert.Equal(t, 0x40, d.defaultAddress) } func TestINA3221Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewINA3221Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestINA3221Start(t *testing.T) { d := NewINA3221Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestINA3221Halt(t *testing.T) { d, _ := initTestINA3221DriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestINA3221GetBusVoltage(t *testing.T) { @@ -61,8 +61,8 @@ func TestINA3221GetBusVoltage(t *testing.T) { } v, err := d.GetBusVoltage(INA3221Channel1) - gobottest.Assert(t, v, float64(13.928)) - gobottest.Assert(t, err, nil) + assert.Equal(t, float64(13.928), v) + assert.Nil(t, err) } func TestINA3221GetBusVoltageReadError(t *testing.T) { @@ -72,7 +72,7 @@ func TestINA3221GetBusVoltageReadError(t *testing.T) { } _, err := d.GetBusVoltage(INA3221Channel1) - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestINA3221GetShuntVoltage(t *testing.T) { @@ -84,8 +84,8 @@ func TestINA3221GetShuntVoltage(t *testing.T) { } v, err := d.GetShuntVoltage(INA3221Channel1) - gobottest.Assert(t, v, float64(7.48)) - gobottest.Assert(t, err, nil) + assert.Equal(t, float64(7.48), v) + assert.Nil(t, err) } func TestINA3221GetShuntVoltageReadError(t *testing.T) { @@ -95,7 +95,7 @@ func TestINA3221GetShuntVoltageReadError(t *testing.T) { } _, err := d.GetShuntVoltage(INA3221Channel1) - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestINA3221GetCurrent(t *testing.T) { @@ -107,8 +107,8 @@ func TestINA3221GetCurrent(t *testing.T) { } v, err := d.GetCurrent(INA3221Channel1) - gobottest.Assert(t, v, float64(74.8)) - gobottest.Assert(t, err, nil) + assert.Equal(t, float64(74.8), v) + assert.Nil(t, err) } func TestINA3221CurrentReadError(t *testing.T) { @@ -118,7 +118,7 @@ func TestINA3221CurrentReadError(t *testing.T) { } _, err := d.GetCurrent(INA3221Channel1) - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestINA3221GetLoadVoltage(t *testing.T) { @@ -132,8 +132,8 @@ func TestINA3221GetLoadVoltage(t *testing.T) { } v, err := d.GetLoadVoltage(INA3221Channel2) - gobottest.Assert(t, v, float64(13.935480)) - gobottest.Assert(t, err, nil) + assert.Equal(t, float64(13.935480), v) + assert.Nil(t, err) } func TestINA3221GetLoadVoltageReadError(t *testing.T) { @@ -143,5 +143,5 @@ func TestINA3221GetLoadVoltageReadError(t *testing.T) { } _, err := d.GetLoadVoltage(INA3221Channel2) - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } diff --git a/drivers/i2c/jhd1313m1_driver_test.go b/drivers/i2c/jhd1313m1_driver_test.go index 1c0c99fc9..858689dd6 100644 --- a/drivers/i2c/jhd1313m1_driver_test.go +++ b/drivers/i2c/jhd1313m1_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*JHD1313M1Driver)(nil) @@ -37,30 +37,30 @@ func TestNewJHD1313M1Driver(t *testing.T) { func TestJHD1313M1Driver(t *testing.T) { jhd := initTestJHD1313M1Driver() - gobottest.Refute(t, jhd.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(jhd.Name(), "JHD1313M1"), true) + assert.NotNil(t, jhd.Connection()) + assert.True(t, strings.HasPrefix(jhd.Name(), "JHD1313M1")) } func TestJHD1313MDriverSetName(t *testing.T) { d := initTestJHD1313M1Driver() d.SetName("TESTME") - gobottest.Assert(t, d.Name(), "TESTME") + assert.Equal(t, "TESTME", d.Name()) } func TestJHD1313MDriverOptions(t *testing.T) { d := NewJHD1313M1Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestJHD1313MDriverStart(t *testing.T) { d := initTestJHD1313M1Driver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestJHD1313MStartConnectError(t *testing.T) { d, adaptor := initTestJHD1313M1DriverWithStubbedAdaptor() adaptor.Testi2cConnectErr(true) - gobottest.Assert(t, d.Start(), errors.New("Invalid i2c connection")) + assert.Errorf(t, d.Start(), "Invalid i2c connection") } func TestJHD1313MDriverStartWriteError(t *testing.T) { @@ -68,19 +68,19 @@ func TestJHD1313MDriverStartWriteError(t *testing.T) { adaptor.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Start(), errors.New("write error")) + assert.Errorf(t, d.Start(), "write error") } func TestJHD1313MDriverHalt(t *testing.T) { d := initTestJHD1313M1Driver() _ = d.Start() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestJHD1313MDriverSetRgb(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.SetRGB(0x00, 0x00, 0x00), nil) + assert.Nil(t, d.SetRGB(0x00, 0x00, 0x00)) } func TestJHD1313MDriverSetRgbError(t *testing.T) { @@ -90,13 +90,13 @@ func TestJHD1313MDriverSetRgbError(t *testing.T) { a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.SetRGB(0x00, 0x00, 0x00), errors.New("write error")) + assert.Errorf(t, d.SetRGB(0x00, 0x00, 0x00), "write error") } func TestJHD1313MDriverClear(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Clear(), nil) + assert.Nil(t, d.Clear()) } func TestJHD1313MDriverClearError(t *testing.T) { @@ -106,19 +106,19 @@ func TestJHD1313MDriverClearError(t *testing.T) { a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Clear(), errors.New("write error")) + assert.Errorf(t, d.Clear(), "write error") } func TestJHD1313MDriverHome(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Home(), nil) + assert.Nil(t, d.Home()) } func TestJHD1313MDriverWrite(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Write("Hello"), nil) + assert.Nil(t, d.Write("Hello")) } func TestJHD1313MDriverWriteError(t *testing.T) { @@ -128,13 +128,13 @@ func TestJHD1313MDriverWriteError(t *testing.T) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Write("Hello"), errors.New("write error")) + assert.Errorf(t, d.Write("Hello"), "write error") } func TestJHD1313MDriverWriteTwoLines(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Write("Hello\nthere"), nil) + assert.Nil(t, d.Write("Hello\nthere")) } func TestJHD1313MDriverWriteTwoLinesError(t *testing.T) { @@ -144,52 +144,52 @@ func TestJHD1313MDriverWriteTwoLinesError(t *testing.T) { a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.Write("Hello\nthere"), errors.New("write error")) + assert.Errorf(t, d.Write("Hello\nthere"), "write error") } func TestJHD1313MDriverSetPosition(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.SetPosition(2), nil) + assert.Nil(t, d.SetPosition(2)) } func TestJHD1313MDriverSetSecondLinePosition(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.SetPosition(18), nil) + assert.Nil(t, d.SetPosition(18)) } func TestJHD1313MDriverSetPositionInvalid(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.SetPosition(-1), jhd1313m1ErrInvalidPosition) - gobottest.Assert(t, d.SetPosition(32), jhd1313m1ErrInvalidPosition) + assert.Equal(t, jhd1313m1ErrInvalidPosition, d.SetPosition(-1)) + assert.Equal(t, jhd1313m1ErrInvalidPosition, d.SetPosition(32)) } func TestJHD1313MDriverScroll(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Scroll(true), nil) + assert.Nil(t, d.Scroll(true)) } func TestJHD1313MDriverReverseScroll(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() _ = d.Start() - gobottest.Assert(t, d.Scroll(false), nil) + assert.Nil(t, d.Scroll(false)) } func TestJHD1313MDriverSetCustomChar(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() data := [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} _ = d.Start() - gobottest.Assert(t, d.SetCustomChar(0, data), nil) + assert.Nil(t, d.SetCustomChar(0, data)) } func TestJHD1313MDriverSetCustomCharError(t *testing.T) { d, _ := initTestJHD1313M1DriverWithStubbedAdaptor() data := [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} _ = d.Start() - gobottest.Assert(t, d.SetCustomChar(10, data), errors.New("can't set a custom character at a position greater than 7")) + assert.Errorf(t, d.SetCustomChar(10, data), "can't set a custom character at a position greater than 7") } func TestJHD1313MDriverSetCustomCharWriteError(t *testing.T) { @@ -200,7 +200,7 @@ func TestJHD1313MDriverSetCustomCharWriteError(t *testing.T) { return 0, errors.New("write error") } data := [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - gobottest.Assert(t, d.SetCustomChar(0, data), errors.New("write error")) + assert.Errorf(t, d.SetCustomChar(0, data), "write error") } func TestJHD1313MDriverCommands(t *testing.T) { @@ -208,20 +208,20 @@ func TestJHD1313MDriverCommands(t *testing.T) { _ = d.Start() err := d.Command("SetRGB")(map[string]interface{}{"r": "1", "g": "1", "b": "1"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("Clear")(map[string]interface{}{}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("Home")(map[string]interface{}{}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("Write")(map[string]interface{}{"msg": "Hello"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("SetPosition")(map[string]interface{}{"pos": "1"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("Scroll")(map[string]interface{}{"lr": "true"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } diff --git a/drivers/i2c/l3gd20h_driver_test.go b/drivers/i2c/l3gd20h_driver_test.go index 892891698..01a3cf728 100644 --- a/drivers/i2c/l3gd20h_driver_test.go +++ b/drivers/i2c/l3gd20h_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -33,17 +33,17 @@ func TestNewL3GD20HDriver(t *testing.T) { if !ok { t.Errorf("NewL3GD20HDriver() should have returned a *L3GD20HDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "L3GD20H"), true) - gobottest.Assert(t, d.defaultAddress, 0x6b) - gobottest.Assert(t, d.Scale(), L3GD20HScale250dps) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "L3GD20H")) + assert.Equal(t, 0x6b, d.defaultAddress) + assert.Equal(t, L3GD20HScale250dps, d.Scale()) } func TestL3GD20HOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option. // Further tests for options can also be done by call of "WithOption(val)(d)". d := NewL3GD20HDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestL3GD20HWithL3GD20HFullScaleRange(t *testing.T) { @@ -75,7 +75,7 @@ func TestL3GD20HWithL3GD20HFullScaleRange(t *testing.T) { // act WithL3GD20HFullScaleRange(tc.scale)(d) // assert - gobottest.Assert(t, d.scale, L3GD20HScale(tc.want)) + assert.Equal(t, L3GD20HScale(tc.want), d.scale) }) } } @@ -109,7 +109,7 @@ func TestL3GD20HScale(t *testing.T) { // act d.SetScale(tc.scale) // assert - gobottest.Assert(t, d.scale, L3GD20HScale(tc.want)) + assert.Equal(t, L3GD20HScale(tc.want), d.scale) }) } } @@ -130,10 +130,10 @@ func TestL3GD20HFullScaleRange(t *testing.T) { // act got, err := d.FullScaleRange() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x23)) - gobottest.Assert(t, got, readValue) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x23), a.written[0]) + assert.Equal(t, readValue, got) } func TestL3GD20HMeasurement(t *testing.T) { @@ -196,12 +196,12 @@ func TestL3GD20HMeasurement(t *testing.T) { // act x, y, z, err := d.XYZ() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0xA8)) - gobottest.Assert(t, x, tc.wantX) - gobottest.Assert(t, y, tc.wantY) - gobottest.Assert(t, z, tc.wantZ) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0xA8), a.written[0]) + assert.Equal(t, tc.wantX, x) + assert.Equal(t, tc.wantY, y) + assert.Equal(t, tc.wantZ, z) }) } } @@ -214,7 +214,7 @@ func TestL3GD20HMeasurementError(t *testing.T) { _ = d.Start() _, _, _, err := d.XYZ() - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestL3GD20HMeasurementWriteError(t *testing.T) { @@ -223,7 +223,7 @@ func TestL3GD20HMeasurementWriteError(t *testing.T) { return 0, errors.New("write error") } _, _, _, err := d.XYZ() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestL3GD20H_initialize(t *testing.T) { @@ -250,11 +250,11 @@ func TestL3GD20H_initialize(t *testing.T) { // arrange, act - initialize() must be called on Start() _, a := initL3GD20HWithStubbedAdaptor() // assert - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], uint8(0x20)) - gobottest.Assert(t, a.written[1], uint8(0x00)) - gobottest.Assert(t, a.written[2], uint8(0x20)) - gobottest.Assert(t, a.written[3], uint8(0x0F)) - gobottest.Assert(t, a.written[4], uint8(0x23)) - gobottest.Assert(t, a.written[5], uint8(0x00)) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, uint8(0x20), a.written[0]) + assert.Equal(t, uint8(0x00), a.written[1]) + assert.Equal(t, uint8(0x20), a.written[2]) + assert.Equal(t, uint8(0x0F), a.written[3]) + assert.Equal(t, uint8(0x23), a.written[4]) + assert.Equal(t, uint8(0x00), a.written[5]) } diff --git a/drivers/i2c/lidarlite_driver_test.go b/drivers/i2c/lidarlite_driver_test.go index 9a570fb2c..d3311822f 100644 --- a/drivers/i2c/lidarlite_driver_test.go +++ b/drivers/i2c/lidarlite_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -34,26 +34,26 @@ func TestNewLIDARLiteDriver(t *testing.T) { if !ok { t.Errorf("NewLIDARLiteDriver() should have returned a *LIDARLiteDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "LIDARLite"), true) - gobottest.Assert(t, d.defaultAddress, 0x62) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "LIDARLite")) + assert.Equal(t, 0x62, d.defaultAddress) } func TestLIDARLiteDriverOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewLIDARLiteDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestLIDARLiteDriverStart(t *testing.T) { d := NewLIDARLiteDriver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestLIDARLiteDriverHalt(t *testing.T) { d := initTestLIDARLiteDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestLIDARLiteDriverDistance(t *testing.T) { @@ -72,8 +72,8 @@ func TestLIDARLiteDriverDistance(t *testing.T) { distance, err := d.Distance() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, distance, int(25345)) + assert.Nil(t, err) + assert.Equal(t, int(25345), distance) // when insufficient bytes have been read d, a = initTestLIDARLiteDriverWithStubbedAdaptor() @@ -82,8 +82,8 @@ func TestLIDARLiteDriverDistance(t *testing.T) { } distance, err = d.Distance() - gobottest.Assert(t, distance, int(0)) - gobottest.Assert(t, err, ErrNotEnoughBytes) + assert.Equal(t, int(0), distance) + assert.Equal(t, ErrNotEnoughBytes, err) // when read error d, a = initTestLIDARLiteDriverWithStubbedAdaptor() @@ -92,8 +92,8 @@ func TestLIDARLiteDriverDistance(t *testing.T) { } distance, err = d.Distance() - gobottest.Assert(t, distance, int(0)) - gobottest.Assert(t, err, errors.New("read error")) + assert.Equal(t, int(0), distance) + assert.Errorf(t, err, "read error") } func TestLIDARLiteDriverDistanceError1(t *testing.T) { @@ -103,8 +103,8 @@ func TestLIDARLiteDriverDistanceError1(t *testing.T) { } distance, err := d.Distance() - gobottest.Assert(t, distance, int(0)) - gobottest.Assert(t, err, errors.New("write error")) + assert.Equal(t, int(0), distance) + assert.Errorf(t, err, "write error") } func TestLIDARLiteDriverDistanceError2(t *testing.T) { @@ -117,8 +117,8 @@ func TestLIDARLiteDriverDistanceError2(t *testing.T) { } distance, err := d.Distance() - gobottest.Assert(t, distance, int(0)) - gobottest.Assert(t, err, errors.New("write error")) + assert.Equal(t, int(0), distance) + assert.Errorf(t, err, "write error") } func TestLIDARLiteDriverDistanceError3(t *testing.T) { @@ -137,6 +137,6 @@ func TestLIDARLiteDriverDistanceError3(t *testing.T) { } distance, err := d.Distance() - gobottest.Assert(t, distance, int(0)) - gobottest.Assert(t, err, errors.New("write error")) + assert.Equal(t, int(0), distance) + assert.Errorf(t, err, "write error") } diff --git a/drivers/i2c/mcp23017_driver_test.go b/drivers/i2c/mcp23017_driver_test.go index a682c0caf..220df3272 100644 --- a/drivers/i2c/mcp23017_driver_test.go +++ b/drivers/i2c/mcp23017_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -45,56 +45,56 @@ func TestNewMCP23017Driver(t *testing.T) { if !ok { t.Errorf("NewMCP23017Driver() should have returned a *MCP23017Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MCP23017"), true) - gobottest.Assert(t, d.defaultAddress, 0x20) - gobottest.Refute(t, d.mcpConf, nil) - gobottest.Refute(t, d.mcpBehav, nil) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "MCP23017")) + assert.Equal(t, 0x20, d.defaultAddress) + assert.NotNil(t, d.mcpConf) + assert.NotNil(t, d.mcpBehav) } func TestWithMCP23017Bank(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Bank(1)) - gobottest.Assert(t, b.mcpConf.bank, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.bank) } func TestWithMCP23017Mirror(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Mirror(1)) - gobottest.Assert(t, b.mcpConf.mirror, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.mirror) } func TestWithMCP23017Seqop(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Seqop(1)) - gobottest.Assert(t, b.mcpConf.seqop, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.seqop) } func TestWithMCP23017Disslw(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Disslw(1)) - gobottest.Assert(t, b.mcpConf.disslw, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.disslw) } func TestWithMCP23017Haen(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Haen(1)) - gobottest.Assert(t, b.mcpConf.haen, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.haen) } func TestWithMCP23017Odr(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Odr(1)) - gobottest.Assert(t, b.mcpConf.odr, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.odr) } func TestWithMCP23017Intpol(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017Intpol(1)) - gobottest.Assert(t, b.mcpConf.intpol, uint8(1)) + assert.Equal(t, uint8(1), b.mcpConf.intpol) } func TestWithMCP23017ForceRefresh(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017ForceRefresh(1)) - gobottest.Assert(t, b.mcpBehav.forceRefresh, true) + assert.True(t, b.mcpBehav.forceRefresh) } func TestWithMCP23017AutoIODirOff(t *testing.T) { b := NewMCP23017Driver(newI2cTestAdaptor(), WithMCP23017AutoIODirOff(1)) - gobottest.Assert(t, b.mcpBehav.autoIODirOff, true) + assert.True(t, b.mcpBehav.autoIODirOff) } func TestMCP23017CommandsWriteGPIO(t *testing.T) { @@ -103,7 +103,7 @@ func TestMCP23017CommandsWriteGPIO(t *testing.T) { // act result := d.Command("WriteGPIO")(pinValPort) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestMCP23017CommandsReadGPIO(t *testing.T) { @@ -112,7 +112,7 @@ func TestMCP23017CommandsReadGPIO(t *testing.T) { // act result := d.Command("ReadGPIO")(pinPort) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestMCP23017WriteGPIO(t *testing.T) { @@ -147,15 +147,15 @@ func TestMCP23017WriteGPIO(t *testing.T) { // act err := d.WriteGPIO(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], wantReg1) - gobottest.Assert(t, a.written[1], wantReg1) - gobottest.Assert(t, a.written[2], wantReg1Val) - gobottest.Assert(t, a.written[3], wantReg2) - gobottest.Assert(t, a.written[4], wantReg2) - gobottest.Assert(t, a.written[5], wantReg2Val) - gobottest.Assert(t, numCallsRead, 2) + assert.Nil(t, err) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, wantReg1, a.written[0]) + assert.Equal(t, wantReg1, a.written[1]) + assert.Equal(t, wantReg1Val, a.written[2]) + assert.Equal(t, wantReg2, a.written[3]) + assert.Equal(t, wantReg2, a.written[4]) + assert.Equal(t, wantReg2Val, a.written[5]) + assert.Equal(t, 2, numCallsRead) } } @@ -186,11 +186,11 @@ func TestMCP23017WriteGPIONoRefresh(t *testing.T) { // act err := d.WriteGPIO(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg1) - gobottest.Assert(t, a.written[1], wantReg2) - gobottest.Assert(t, numCallsRead, 2) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg1, a.written[0]) + assert.Equal(t, wantReg2, a.written[1]) + assert.Equal(t, 2, numCallsRead) } } @@ -223,12 +223,12 @@ func TestMCP23017WriteGPIONoAutoDir(t *testing.T) { // act err := d.WriteGPIO(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 3) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantReg) - gobottest.Assert(t, a.written[2], wantRegVal) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, 3, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantReg, a.written[1]) + assert.Equal(t, wantRegVal, a.written[2]) + assert.Equal(t, 1, numCallsRead) } } @@ -241,7 +241,7 @@ func TestMCP23017CommandsWriteGPIOErrIODIR(t *testing.T) { // act err := d.WriteGPIO(7, "A", 0) // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=0): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=0): write error") } func TestMCP23017CommandsWriteGPIOErrOLAT(t *testing.T) { @@ -258,7 +258,7 @@ func TestMCP23017CommandsWriteGPIOErrOLAT(t *testing.T) { // act err := d.WriteGPIO(7, "A", 0) // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=20): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=20): write error") } func TestMCP23017ReadGPIO(t *testing.T) { @@ -290,14 +290,14 @@ func TestMCP23017ReadGPIO(t *testing.T) { // act val, err := d.ReadGPIO(testPin, testPort) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, len(a.written), 4) - gobottest.Assert(t, a.written[0], wantReg1) - gobottest.Assert(t, a.written[1], wantReg1) - gobottest.Assert(t, a.written[2], wantReg1Val) - gobottest.Assert(t, a.written[3], wantReg2) - gobottest.Assert(t, val, uint8(bitState)) + assert.Nil(t, err) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, 4, len(a.written)) + assert.Equal(t, wantReg1, a.written[0]) + assert.Equal(t, wantReg1, a.written[1]) + assert.Equal(t, wantReg1Val, a.written[2]) + assert.Equal(t, wantReg2, a.written[3]) + assert.Equal(t, uint8(bitState), val) } } @@ -328,12 +328,12 @@ func TestMCP23017ReadGPIONoRefresh(t *testing.T) { // act val, err := d.ReadGPIO(testPin, testPort) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantReg1) - gobottest.Assert(t, a.written[1], wantReg2) - gobottest.Assert(t, val, uint8(bitState)) + assert.Nil(t, err) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantReg1, a.written[0]) + assert.Equal(t, wantReg2, a.written[1]) + assert.Equal(t, uint8(bitState), val) } } @@ -363,11 +363,11 @@ func TestMCP23017ReadGPIONoAutoDir(t *testing.T) { // act val, err := d.ReadGPIO(testPin, testPort) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], wantReg2) - gobottest.Assert(t, val, uint8(bitState)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, wantReg2, a.written[0]) + assert.Equal(t, uint8(bitState), val) } } @@ -381,7 +381,7 @@ func TestMCP23017ReadGPIOErr(t *testing.T) { // act _, err := d.ReadGPIO(7, "A") // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=0): read error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=0): read error") } func TestMCP23017SetPinMode(t *testing.T) { @@ -413,12 +413,12 @@ func TestMCP23017SetPinMode(t *testing.T) { // act err := d.SetPinMode(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 3) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantReg) - gobottest.Assert(t, a.written[2], wantRegVal) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, 3, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantReg, a.written[1]) + assert.Equal(t, wantRegVal, a.written[2]) + assert.Equal(t, 1, numCallsRead) } } @@ -431,7 +431,7 @@ func TestMCP23017SetPinModeErr(t *testing.T) { // act err := d.SetPinMode(7, "A", 0) // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=0): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=0): write error") } func TestMCP23017SetPullUp(t *testing.T) { @@ -463,12 +463,12 @@ func TestMCP23017SetPullUp(t *testing.T) { // act err := d.SetPullUp(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 3) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantReg) - gobottest.Assert(t, a.written[2], wantSetVal) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, 3, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantReg, a.written[1]) + assert.Equal(t, wantSetVal, a.written[2]) + assert.Equal(t, 1, numCallsRead) } } @@ -481,7 +481,7 @@ func TestMCP23017SetPullUpErr(t *testing.T) { // act err := d.SetPullUp(7, "A", 0) // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=12): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=12): write error") } func TestMCP23017SetGPIOPolarity(t *testing.T) { @@ -513,12 +513,12 @@ func TestMCP23017SetGPIOPolarity(t *testing.T) { // act err := d.SetGPIOPolarity(testPin, testPort, uint8(bitState)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 3) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, a.written[1], wantReg) - gobottest.Assert(t, a.written[2], wantSetVal) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, 3, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, wantReg, a.written[1]) + assert.Equal(t, wantSetVal, a.written[2]) + assert.Equal(t, 1, numCallsRead) } } @@ -531,7 +531,7 @@ func TestMCP23017SetGPIOPolarityErr(t *testing.T) { // act err := d.SetGPIOPolarity(7, "A", 0) // assert - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=2): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=2): write error") } func TestMCP23017_write(t *testing.T) { @@ -539,13 +539,13 @@ func TestMCP23017_write(t *testing.T) { d, _ := initTestMCP23017WithStubbedAdaptor(0) port := d.getPort("A") err := d.write(port.IODIR, uint8(7), 0) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) // set bit d, _ = initTestMCP23017WithStubbedAdaptor(0) port = d.getPort("B") err = d.write(port.IODIR, uint8(7), 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) // write error d, a := initTestMCP23017WithStubbedAdaptor(0) @@ -553,7 +553,7 @@ func TestMCP23017_write(t *testing.T) { return 0, errors.New("write error") } err = d.write(port.IODIR, uint8(7), 0) - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=1): write error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=1): write error") // read error d, a = initTestMCP23017WithStubbedAdaptor(0) @@ -561,12 +561,12 @@ func TestMCP23017_write(t *testing.T) { return len(b), errors.New("read error") } err = d.write(port.IODIR, uint8(7), 0) - gobottest.Assert(t, err, errors.New("MCP write-read: MCP write-ReadByteData(reg=1): read error")) + assert.Errorf(t, err, "MCP write-read: MCP write-ReadByteData(reg=1): read error") a.i2cReadImpl = func(b []byte) (int, error) { return len(b), nil } err = d.write(port.IODIR, uint8(7), 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestMCP23017_read(t *testing.T) { @@ -578,7 +578,7 @@ func TestMCP23017_read(t *testing.T) { return 1, nil } val, _ := d.read(port.IODIR) - gobottest.Assert(t, val, uint8(255)) + assert.Equal(t, uint8(255), val) // read error d, a = initTestMCP23017WithStubbedAdaptor(0) @@ -587,8 +587,8 @@ func TestMCP23017_read(t *testing.T) { } val, err := d.read(port.IODIR) - gobottest.Assert(t, val, uint8(0)) - gobottest.Assert(t, err, errors.New("MCP write-ReadByteData(reg=0): read error")) + assert.Equal(t, uint8(0), val) + assert.Errorf(t, err, "MCP write-ReadByteData(reg=0): read error") // read d, a = initTestMCP23017WithStubbedAdaptor(0) @@ -598,7 +598,7 @@ func TestMCP23017_read(t *testing.T) { return 1, nil } val, _ = d.read(port.IODIR) - gobottest.Assert(t, val, uint8(255)) + assert.Equal(t, uint8(255), val) } func TestMCP23017_getPort(t *testing.T) { @@ -606,23 +606,23 @@ func TestMCP23017_getPort(t *testing.T) { d := initTestMCP23017(0) expectedPort := mcp23017GetBank(0).portA actualPort := d.getPort("A") - gobottest.Assert(t, expectedPort, actualPort) + assert.Equal(t, actualPort, expectedPort) // port B d = initTestMCP23017(0) expectedPort = mcp23017GetBank(0).portB actualPort = d.getPort("B") - gobottest.Assert(t, expectedPort, actualPort) + assert.Equal(t, actualPort, expectedPort) // default d = initTestMCP23017(0) expectedPort = mcp23017GetBank(0).portA actualPort = d.getPort("") - gobottest.Assert(t, expectedPort, actualPort) + assert.Equal(t, actualPort, expectedPort) // port A bank 1 d = initTestMCP23017(1) expectedPort = mcp23017GetBank(1).portA actualPort = d.getPort("") - gobottest.Assert(t, expectedPort, actualPort) + assert.Equal(t, actualPort, expectedPort) } diff --git a/drivers/i2c/mma7660_driver_test.go b/drivers/i2c/mma7660_driver_test.go index d44d0fa87..44529c6b6 100644 --- a/drivers/i2c/mma7660_driver_test.go +++ b/drivers/i2c/mma7660_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -29,43 +29,43 @@ func TestNewMMA7660Driver(t *testing.T) { if !ok { t.Errorf("NewMMA7660Driver() should have returned a *MMA7660Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MMA7660"), true) - gobottest.Assert(t, d.defaultAddress, 0x4c) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "MMA7660")) + assert.Equal(t, 0x4c, d.defaultAddress) } func TestMMA7660Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewMMA7660Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestMMA7660Start(t *testing.T) { d := NewMMA7660Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestMMA7660Halt(t *testing.T) { d, _ := initTestMMA7660DriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestMMA7660Acceleration(t *testing.T) { d, _ := initTestMMA7660DriverWithStubbedAdaptor() x, y, z := d.Acceleration(21.0, 21.0, 21.0) - gobottest.Assert(t, x, 1.0) - gobottest.Assert(t, y, 1.0) - gobottest.Assert(t, z, 1.0) + assert.Equal(t, 1.0, x) + assert.Equal(t, 1.0, y) + assert.Equal(t, 1.0, z) } func TestMMA7660NullXYZ(t *testing.T) { d, _ := initTestMMA7660DriverWithStubbedAdaptor() x, y, z, _ := d.XYZ() - gobottest.Assert(t, x, 0.0) - gobottest.Assert(t, y, 0.0) - gobottest.Assert(t, z, 0.0) + assert.Equal(t, 0.0, x) + assert.Equal(t, 0.0, y) + assert.Equal(t, 0.0, z) } func TestMMA7660XYZ(t *testing.T) { @@ -78,9 +78,9 @@ func TestMMA7660XYZ(t *testing.T) { } x, y, z, _ := d.XYZ() - gobottest.Assert(t, x, 17.0) - gobottest.Assert(t, y, 18.0) - gobottest.Assert(t, z, 19.0) + assert.Equal(t, 17.0, x) + assert.Equal(t, 18.0, y) + assert.Equal(t, 19.0, z) } func TestMMA7660XYZError(t *testing.T) { @@ -90,7 +90,7 @@ func TestMMA7660XYZError(t *testing.T) { } _, _, _, err := d.XYZ() - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestMMA7660XYZNotReady(t *testing.T) { @@ -103,5 +103,5 @@ func TestMMA7660XYZNotReady(t *testing.T) { } _, _, _, err := d.XYZ() - gobottest.Assert(t, err, ErrNotReady) + assert.Equal(t, ErrNotReady, err) } diff --git a/drivers/i2c/mpl115a2_driver_test.go b/drivers/i2c/mpl115a2_driver_test.go index 6891e9e47..14a4fb86a 100644 --- a/drivers/i2c/mpl115a2_driver_test.go +++ b/drivers/i2c/mpl115a2_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -24,16 +24,16 @@ func TestNewMPL115A2Driver(t *testing.T) { if !ok { t.Errorf("NewMPL115A2Driver() should have returned a *MPL115A2Driver") } - gobottest.Refute(t, d.Connection(), nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MPL115A2"), true) - gobottest.Assert(t, d.defaultAddress, 0x60) + assert.NotNil(t, d.Connection()) + assert.True(t, strings.HasPrefix(d.Name(), "MPL115A2")) + assert.Equal(t, 0x60, d.defaultAddress) } func TestMPL115A2Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewMPL115A2Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestMPL115A2ReadData(t *testing.T) { @@ -78,18 +78,18 @@ func TestMPL115A2ReadData(t *testing.T) { press, errP := d.Pressure() temp, errT := d.Temperature() // assert - gobottest.Assert(t, errP, nil) - gobottest.Assert(t, errT, nil) - gobottest.Assert(t, readCallCounter, 2) - gobottest.Assert(t, len(a.written), 6) - gobottest.Assert(t, a.written[0], uint8(0x12)) - gobottest.Assert(t, a.written[1], uint8(0x00)) - gobottest.Assert(t, a.written[2], uint8(0x00)) - gobottest.Assert(t, a.written[3], uint8(0x12)) - gobottest.Assert(t, a.written[4], uint8(0x00)) - gobottest.Assert(t, a.written[5], uint8(0x00)) - gobottest.Assert(t, press, float32(96.585915)) - gobottest.Assert(t, temp, float32(23.317757)) + assert.Nil(t, errP) + assert.Nil(t, errT) + assert.Equal(t, 2, readCallCounter) + assert.Equal(t, 6, len(a.written)) + assert.Equal(t, uint8(0x12), a.written[0]) + assert.Equal(t, uint8(0x00), a.written[1]) + assert.Equal(t, uint8(0x00), a.written[2]) + assert.Equal(t, uint8(0x12), a.written[3]) + assert.Equal(t, uint8(0x00), a.written[4]) + assert.Equal(t, uint8(0x00), a.written[5]) + assert.Equal(t, float32(96.585915), press) + assert.Equal(t, float32(23.317757), temp) } func TestMPL115A2ReadDataError(t *testing.T) { @@ -101,7 +101,7 @@ func TestMPL115A2ReadDataError(t *testing.T) { } _, err := d.Pressure() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestMPL115A2_initialization(t *testing.T) { @@ -124,12 +124,12 @@ func TestMPL115A2_initialization(t *testing.T) { // act, assert - initialization() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, readCallCounter, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x04)) - gobottest.Assert(t, d.a0, float32(2009.75)) - gobottest.Assert(t, d.b1, float32(-2.3758545)) - gobottest.Assert(t, d.b2, float32(-0.9204712)) - gobottest.Assert(t, d.c12, float32(0.0007901192)) + assert.Nil(t, err) + assert.Equal(t, 1, readCallCounter) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x04), a.written[0]) + assert.Equal(t, float32(2009.75), d.a0) + assert.Equal(t, float32(-2.3758545), d.b1) + assert.Equal(t, float32(-0.9204712), d.b2) + assert.Equal(t, float32(0.0007901192), d.c12) } diff --git a/drivers/i2c/mpu6050_driver_test.go b/drivers/i2c/mpu6050_driver_test.go index ac9a3ec9a..905663829 100644 --- a/drivers/i2c/mpu6050_driver_test.go +++ b/drivers/i2c/mpu6050_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,48 +28,48 @@ func TestNewMPU6050Driver(t *testing.T) { if !ok { t.Errorf("NewMPU6050Driver() should have returned a *MPU6050Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.name, "MPU6050"), true) - gobottest.Assert(t, d.defaultAddress, 0x68) - gobottest.Assert(t, d.dlpf, MPU6050DlpfConfig(0x00)) - gobottest.Assert(t, d.frameSync, MPU6050FrameSyncConfig(0x00)) - gobottest.Assert(t, d.accelFs, MPU6050AccelFsConfig(0x00)) - gobottest.Assert(t, d.gyroFs, MPU6050GyroFsConfig(0x00)) - gobottest.Assert(t, d.clock, MPU6050Pwr1ClockConfig(0x01)) - gobottest.Assert(t, d.gravity, 9.80665) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.name, "MPU6050")) + assert.Equal(t, 0x68, d.defaultAddress) + assert.Equal(t, MPU6050DlpfConfig(0x00), d.dlpf) + assert.Equal(t, MPU6050FrameSyncConfig(0x00), d.frameSync) + assert.Equal(t, MPU6050AccelFsConfig(0x00), d.accelFs) + assert.Equal(t, MPU6050GyroFsConfig(0x00), d.gyroFs) + assert.Equal(t, MPU6050Pwr1ClockConfig(0x01), d.clock) + assert.Equal(t, 9.80665, d.gravity) } func TestMPU6050Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewMPU6050Driver(newI2cTestAdaptor(), WithBus(2), WithMPU6050DigitalFilter(0x06)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.dlpf, MPU6050DlpfConfig(0x06)) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, MPU6050DlpfConfig(0x06), d.dlpf) } func TestWithMPU6050FrameSync(t *testing.T) { d := NewMPU6050Driver(newI2cTestAdaptor(), WithMPU6050FrameSync(0x07)) - gobottest.Assert(t, d.frameSync, MPU6050FrameSyncConfig(0x07)) + assert.Equal(t, MPU6050FrameSyncConfig(0x07), d.frameSync) } func TestWithMPU6050AccelFullScaleRange(t *testing.T) { d := NewMPU6050Driver(newI2cTestAdaptor(), WithMPU6050AccelFullScaleRange(0x02)) - gobottest.Assert(t, d.accelFs, MPU6050AccelFsConfig(0x02)) + assert.Equal(t, MPU6050AccelFsConfig(0x02), d.accelFs) } func TestWithMPU6050GyroFullScaleRange(t *testing.T) { d := NewMPU6050Driver(newI2cTestAdaptor(), WithMPU6050GyroFullScaleRange(0x03)) - gobottest.Assert(t, d.gyroFs, MPU6050GyroFsConfig(0x03)) + assert.Equal(t, MPU6050GyroFsConfig(0x03), d.gyroFs) } func TestWithMPU6050ClockSource(t *testing.T) { d := NewMPU6050Driver(newI2cTestAdaptor(), WithMPU6050ClockSource(0x05)) - gobottest.Assert(t, d.clock, MPU6050Pwr1ClockConfig(0x05)) + assert.Equal(t, MPU6050Pwr1ClockConfig(0x05), d.clock) } func TestWithMPU6050Gravity(t *testing.T) { d := NewMPU6050Driver(newI2cTestAdaptor(), WithMPU6050Gravity(1.0)) - gobottest.Assert(t, d.gravity, 1.0) + assert.Equal(t, 1.0, d.gravity) } func TestMPU6050GetData(t *testing.T) { @@ -111,9 +111,9 @@ func TestMPU6050GetData(t *testing.T) { // act _ = d.GetData() // assert - gobottest.Assert(t, d.Accelerometer, wantAccel) - gobottest.Assert(t, d.Gyroscope, wantGyro) - gobottest.Assert(t, d.Temperature, wantTemp) + assert.Equal(t, wantAccel, d.Accelerometer) + assert.Equal(t, wantGyro, d.Gyroscope) + assert.Equal(t, wantTemp, d.Temperature) } func TestMPU6050GetDataReadError(t *testing.T) { @@ -124,7 +124,7 @@ func TestMPU6050GetDataReadError(t *testing.T) { return 0, errors.New("read error") } - gobottest.Assert(t, d.GetData(), errors.New("read error")) + assert.Errorf(t, d.GetData(), "read error") } func TestMPU6050GetDataWriteError(t *testing.T) { @@ -135,7 +135,7 @@ func TestMPU6050GetDataWriteError(t *testing.T) { return 0, errors.New("write error") } - gobottest.Assert(t, d.GetData(), errors.New("write error")) + assert.Errorf(t, d.GetData(), "write error") } func TestMPU6050_initialize(t *testing.T) { @@ -172,20 +172,20 @@ func TestMPU6050_initialize(t *testing.T) { // act, assert - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, readCallCounter, 1) - gobottest.Assert(t, len(a.written), 13) - gobottest.Assert(t, a.written[0], uint8(0x6B)) - gobottest.Assert(t, a.written[1], uint8(0x80)) - gobottest.Assert(t, a.written[2], uint8(0x6B)) - gobottest.Assert(t, a.written[3], uint8(0x68)) - gobottest.Assert(t, a.written[4], uint8(0x07)) - gobottest.Assert(t, a.written[5], uint8(0x1A)) - gobottest.Assert(t, a.written[6], uint8(0x00)) - gobottest.Assert(t, a.written[7], uint8(0x1B)) - gobottest.Assert(t, a.written[8], uint8(0x00)) - gobottest.Assert(t, a.written[9], uint8(0x1C)) - gobottest.Assert(t, a.written[10], uint8(0x00)) - gobottest.Assert(t, a.written[11], uint8(0x6B)) - gobottest.Assert(t, a.written[12], uint8(0x01)) + assert.Nil(t, err) + assert.Equal(t, 1, readCallCounter) + assert.Equal(t, 13, len(a.written)) + assert.Equal(t, uint8(0x6B), a.written[0]) + assert.Equal(t, uint8(0x80), a.written[1]) + assert.Equal(t, uint8(0x6B), a.written[2]) + assert.Equal(t, uint8(0x68), a.written[3]) + assert.Equal(t, uint8(0x07), a.written[4]) + assert.Equal(t, uint8(0x1A), a.written[5]) + assert.Equal(t, uint8(0x00), a.written[6]) + assert.Equal(t, uint8(0x1B), a.written[7]) + assert.Equal(t, uint8(0x00), a.written[8]) + assert.Equal(t, uint8(0x1C), a.written[9]) + assert.Equal(t, uint8(0x00), a.written[10]) + assert.Equal(t, uint8(0x6B), a.written[11]) + assert.Equal(t, uint8(0x01), a.written[12]) } diff --git a/drivers/i2c/pca9501_driver_test.go b/drivers/i2c/pca9501_driver_test.go index 8446e43eb..33ecb93d7 100644 --- a/drivers/i2c/pca9501_driver_test.go +++ b/drivers/i2c/pca9501_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -47,16 +47,16 @@ func TestNewPCA9501Driver(t *testing.T) { if !ok { t.Errorf("NewPCA9501Driver() should have returned a *PCA9501Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "PCA9501"), true) - gobottest.Assert(t, d.defaultAddress, 0x3f) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "PCA9501")) + assert.Equal(t, 0x3f, d.defaultAddress) } func TestPCA9501Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewPCA9501Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestPCA9501CommandsWriteGPIO(t *testing.T) { @@ -71,7 +71,7 @@ func TestPCA9501CommandsWriteGPIO(t *testing.T) { // act result := d.Command("WriteGPIO")(pinVal) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCA9501CommandsReadGPIO(t *testing.T) { @@ -83,7 +83,7 @@ func TestPCA9501CommandsReadGPIO(t *testing.T) { // act result := d.Command("ReadGPIO")(pin) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCA9501CommandsWriteEEPROM(t *testing.T) { @@ -95,7 +95,7 @@ func TestPCA9501CommandsWriteEEPROM(t *testing.T) { // act result := d.Command("WriteEEPROM")(addressVal) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCA9501CommandsReadEEPROM(t *testing.T) { @@ -110,7 +110,7 @@ func TestPCA9501CommandsReadEEPROM(t *testing.T) { // act result := d.Command("ReadEEPROM")(address) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCA9501WriteGPIO(t *testing.T) { @@ -160,11 +160,11 @@ func TestPCA9501WriteGPIO(t *testing.T) { // act err := d.WriteGPIO(tc.pin, tc.setVal) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], tc.wantPin) - gobottest.Assert(t, a.written[1], tc.wantState) + assert.Nil(t, err) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, tc.wantPin, a.written[0]) + assert.Equal(t, tc.wantState, a.written[1]) }) } } @@ -192,9 +192,9 @@ func TestPCA9501WriteGPIOErrorAtWriteDirection(t *testing.T) { // act err := d.WriteGPIO(7, 0) // assert - gobottest.Assert(t, err, wantErr) - gobottest.Assert(t, numCallsRead < 2, true) - gobottest.Assert(t, numCallsWrite, 1) + assert.Equal(t, wantErr, err) + assert.True(t, numCallsRead < 2) + assert.Equal(t, 1, numCallsWrite) } func TestPCA9501WriteGPIOErrorAtWriteValue(t *testing.T) { @@ -218,8 +218,8 @@ func TestPCA9501WriteGPIOErrorAtWriteValue(t *testing.T) { // act err := d.WriteGPIO(7, 0) // assert - gobottest.Assert(t, err, wantErr) - gobottest.Assert(t, numCallsWrite, 2) + assert.Equal(t, wantErr, err) + assert.Equal(t, 2, numCallsWrite) } func TestPCA9501ReadGPIO(t *testing.T) { @@ -254,11 +254,11 @@ func TestPCA9501ReadGPIO(t *testing.T) { // act got, err := d.ReadGPIO(pin) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], wantCtrlState) + assert.Nil(t, err) + assert.Equal(t, tc.want, got) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, wantCtrlState, a.written[0]) }) } } @@ -286,9 +286,9 @@ func TestPCA9501ReadGPIOErrorAtReadDirection(t *testing.T) { // act _, err := d.ReadGPIO(1) // assert - gobottest.Assert(t, err, wantErr) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, numCallsWrite, 0) + assert.Equal(t, wantErr, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 0, numCallsWrite) } func TestPCA9501ReadGPIOErrorAtReadValue(t *testing.T) { @@ -314,8 +314,8 @@ func TestPCA9501ReadGPIOErrorAtReadValue(t *testing.T) { // act _, err := d.ReadGPIO(2) // assert - gobottest.Assert(t, err, wantErr) - gobottest.Assert(t, numCallsWrite, 1) + assert.Equal(t, wantErr, err) + assert.Equal(t, 1, numCallsWrite) } func TestPCA9501WriteEEPROM(t *testing.T) { @@ -334,10 +334,10 @@ func TestPCA9501WriteEEPROM(t *testing.T) { // act err := d.WriteEEPROM(addressEEPROM, want) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, a.written[0], addressEEPROM) - gobottest.Assert(t, a.written[1], want) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, addressEEPROM, a.written[0]) + assert.Equal(t, want, a.written[1]) } func TestPCA9501ReadEEPROM(t *testing.T) { @@ -363,11 +363,11 @@ func TestPCA9501ReadEEPROM(t *testing.T) { // act val, err := d.ReadEEPROM(addressEEPROM) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, val, want) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, a.written[0], addressEEPROM) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, want, val) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, addressEEPROM, a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCA9501ReadEEPROMErrorWhileWriteAddress(t *testing.T) { @@ -387,8 +387,8 @@ func TestPCA9501ReadEEPROMErrorWhileWriteAddress(t *testing.T) { // act _, err := d.ReadEEPROM(15) // assert - gobottest.Assert(t, err, wantErr) - gobottest.Assert(t, numCallsRead, 0) + assert.Equal(t, wantErr, err) + assert.Equal(t, 0, numCallsRead) } func TestPCA9501ReadEEPROMErrorWhileReadValue(t *testing.T) { @@ -408,8 +408,8 @@ func TestPCA9501ReadEEPROMErrorWhileReadValue(t *testing.T) { // act _, err := d.ReadEEPROM(15) // assert - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, err, wantErr) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, wantErr, err) } func TestPCA9501_initialize(t *testing.T) { @@ -419,6 +419,6 @@ func TestPCA9501_initialize(t *testing.T) { // act err := d.initialize() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, a.address, want) + assert.Nil(t, err) + assert.Equal(t, want, a.address) } diff --git a/drivers/i2c/pca953x_driver_test.go b/drivers/i2c/pca953x_driver_test.go index 0dfd3aa64..20e944b78 100644 --- a/drivers/i2c/pca953x_driver_test.go +++ b/drivers/i2c/pca953x_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -29,9 +29,9 @@ func TestNewPCA953xDriver(t *testing.T) { if !ok { t.Errorf("NewPCA953xDriver() should have returned a *PCA953xDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "PCA953x"), true) - gobottest.Assert(t, d.defaultAddress, 0x63) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "PCA953x")) + assert.Equal(t, 0x63, d.defaultAddress) } func TestPCA953xWriteGPIO(t *testing.T) { @@ -99,8 +99,8 @@ func TestPCA953xWriteGPIO(t *testing.T) { // act err := d.WriteGPIO(tc.idx, tc.val) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -158,10 +158,10 @@ func TestPCA953xReadGPIO(t *testing.T) { // act got, err := d.ReadGPIO(tc.idx) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], wantReg) - gobottest.Assert(t, got, tc.want) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, wantReg, a.written[0]) + assert.Equal(t, tc.want, got) }) } } @@ -200,8 +200,8 @@ func TestPCA953xWritePeriod(t *testing.T) { // act err := d.WritePeriod(tc.idx, tc.val) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Nil(t, err) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -250,9 +250,9 @@ func TestPCA953xReadPeriod(t *testing.T) { // act got, err := d.ReadPeriod(tc.idx) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.want, got) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -291,8 +291,8 @@ func TestPCA953xWriteFrequency(t *testing.T) { // act err := d.WriteFrequency(tc.idx, tc.val) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Nil(t, err) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -341,9 +341,9 @@ func TestPCA953xReadFrequency(t *testing.T) { // act got, err := d.ReadFrequency(tc.idx) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.want, got) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -382,8 +382,8 @@ func TestPCA953xWriteDutyCyclePercent(t *testing.T) { // act err := d.WriteDutyCyclePercent(tc.idx, tc.val) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Nil(t, err) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -432,9 +432,9 @@ func TestPCA953xReadDutyCyclePercent(t *testing.T) { // act got, err := d.ReadDutyCyclePercent(tc.idx) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, a.written, tc.wantWritten) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.want, got) + assert.Equal(t, tc.wantWritten, a.written) }) } } @@ -465,13 +465,13 @@ func TestPCA953x_readRegister(t *testing.T) { // act val, err := d.readRegister(wantRegAddress) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, val, wantRegVal) - gobottest.Assert(t, readByteCount, wantReadByteCount) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(wantRegAddress)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, wantRegVal, val) + assert.Equal(t, wantReadByteCount, readByteCount) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(wantRegAddress), a.written[0]) } func TestPCA953x_writeRegister(t *testing.T) { @@ -491,12 +491,12 @@ func TestPCA953x_writeRegister(t *testing.T) { // act err := d.writeRegister(wantRegAddress, wantRegVal) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, numCallsWrite, 1) - gobottest.Assert(t, len(a.written), wantByteCount) - gobottest.Assert(t, a.written[0], uint8(wantRegAddress)) - gobottest.Assert(t, a.written[1], uint8(wantRegVal)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, 1, numCallsWrite) + assert.Equal(t, wantByteCount, len(a.written)) + assert.Equal(t, uint8(wantRegAddress), a.written[0]) + assert.Equal(t, uint8(wantRegVal), a.written[1]) } func TestPCA953x_pca953xCalcPsc(t *testing.T) { @@ -517,8 +517,8 @@ func TestPCA953x_pca953xCalcPsc(t *testing.T) { // act val, err := pca953xCalcPsc(tc.period) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, val, tc.want) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.want, val) }) } } @@ -539,7 +539,7 @@ func TestPCA953x_pca953xCalcPeriod(t *testing.T) { // act val := pca953xCalcPeriod(tc.psc) // assert - gobottest.Assert(t, float32(math.Round(float64(val)*10000)/10000), tc.want) + assert.Equal(t, tc.want, float32(math.Round(float64(val)*10000)/10000)) }) } } @@ -563,8 +563,8 @@ func TestPCA953x_pca953xCalcPwm(t *testing.T) { // act val, err := pca953xCalcPwm(tc.percent) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, val, tc.want) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.want, val) }) } } @@ -585,7 +585,7 @@ func TestPCA953x_pca953xCalcDutyCyclePercent(t *testing.T) { // act val := pca953xCalcDutyCyclePercent(tc.pwm) // assert - gobottest.Assert(t, float32(math.Round(float64(val)*10)/10), tc.want) + assert.Equal(t, tc.want, float32(math.Round(float64(val)*10)/10)) }) } } diff --git a/drivers/i2c/pca9685_driver_test.go b/drivers/i2c/pca9685_driver_test.go index d77484449..ca448d447 100644 --- a/drivers/i2c/pca9685_driver_test.go +++ b/drivers/i2c/pca9685_driver_test.go @@ -5,9 +5,9 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -33,16 +33,16 @@ func TestNewPCA9685Driver(t *testing.T) { if !ok { t.Errorf("NewPCA9685Driver() should have returned a *PCA9685Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "PCA9685"), true) - gobottest.Assert(t, d.defaultAddress, 0x40) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "PCA9685")) + assert.Equal(t, 0x40, d.defaultAddress) } func TestPCA9685Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewPCA9685Driver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestPCA9685Start(t *testing.T) { @@ -52,7 +52,7 @@ func TestPCA9685Start(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestPCA9685Halt(t *testing.T) { @@ -61,8 +61,8 @@ func TestPCA9685Halt(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestPCA9685SetPWM(t *testing.T) { @@ -71,8 +71,8 @@ func TestPCA9685SetPWM(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.SetPWM(0, 0, 256), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.SetPWM(0, 0, 256)) } func TestPCA9685SetPWMError(t *testing.T) { @@ -81,11 +81,11 @@ func TestPCA9685SetPWMError(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.SetPWM(0, 0, 256), errors.New("write error")) + assert.Errorf(t, d.SetPWM(0, 0, 256), "write error") } func TestPCA9685SetPWMFreq(t *testing.T) { @@ -94,13 +94,13 @@ func TestPCA9685SetPWMFreq(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) a.i2cReadImpl = func(b []byte) (int, error) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.SetPWMFreq(60), nil) + assert.Nil(t, d.SetPWMFreq(60)) } func TestPCA9685SetPWMFreqReadError(t *testing.T) { @@ -109,12 +109,12 @@ func TestPCA9685SetPWMFreqReadError(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) a.i2cReadImpl = func(b []byte) (int, error) { return 0, errors.New("read error") } - gobottest.Assert(t, d.SetPWMFreq(60), errors.New("read error")) + assert.Errorf(t, d.SetPWMFreq(60), "read error") } func TestPCA9685SetPWMFreqWriteError(t *testing.T) { @@ -123,12 +123,12 @@ func TestPCA9685SetPWMFreqWriteError(t *testing.T) { copy(b, []byte{0x01}) return 1, nil } - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.SetPWMFreq(60), errors.New("write error")) + assert.Errorf(t, d.SetPWMFreq(60), "write error") } func TestPCA9685Commands(t *testing.T) { @@ -140,14 +140,14 @@ func TestPCA9685Commands(t *testing.T) { _ = d.Start() err := d.Command("PwmWrite")(map[string]interface{}{"pin": "1", "val": "1"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("ServoWrite")(map[string]interface{}{"pin": "1", "val": "1"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("SetPWM")(map[string]interface{}{"channel": "1", "on": "0", "off": "1024"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = d.Command("SetPWMFreq")(map[string]interface{}{"freq": "60"}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } diff --git a/drivers/i2c/pcf8583_driver_test.go b/drivers/i2c/pcf8583_driver_test.go index c0a6db1d9..a772b1192 100644 --- a/drivers/i2c/pcf8583_driver_test.go +++ b/drivers/i2c/pcf8583_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -26,20 +26,20 @@ func TestNewPCF8583Driver(t *testing.T) { if !ok { t.Errorf("NewPCF8583Driver() should have returned a *PCF8583Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.name, "PCF8583"), true) - gobottest.Assert(t, d.defaultAddress, 0x50) - gobottest.Assert(t, d.mode, PCF8583Control(0x00)) - gobottest.Assert(t, d.yearOffset, 0) - gobottest.Assert(t, d.ramOffset, uint8(0x10)) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.name, "PCF8583")) + assert.Equal(t, 0x50, d.defaultAddress) + assert.Equal(t, PCF8583Control(0x00), d.mode) + assert.Equal(t, 0, d.yearOffset) + assert.Equal(t, uint8(0x10), d.ramOffset) } func TestPCF8583Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewPCF8583Driver(newI2cTestAdaptor(), WithBus(2), WithPCF8583Mode(PCF8583CtrlModeClock50)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.mode, PCF8583CtrlModeClock50) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, PCF8583CtrlModeClock50, d.mode) } func TestPCF8583CommandsWriteTime(t *testing.T) { @@ -60,7 +60,7 @@ func TestPCF8583CommandsWriteTime(t *testing.T) { // act result := d.Command("WriteTime")(map[string]interface{}{"val": time.Now()}) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCF8583CommandsReadTime(t *testing.T) { @@ -94,8 +94,8 @@ func TestPCF8583CommandsReadTime(t *testing.T) { // act result := d.Command("ReadTime")(map[string]interface{}{}) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], want) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, want, result.(map[string]interface{})["val"]) } func TestPCF8583CommandsWriteCounter(t *testing.T) { @@ -116,7 +116,7 @@ func TestPCF8583CommandsWriteCounter(t *testing.T) { // act result := d.Command("WriteCounter")(map[string]interface{}{"val": int32(123456)}) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCF8583CommandsReadCounter(t *testing.T) { @@ -145,8 +145,8 @@ func TestPCF8583CommandsReadCounter(t *testing.T) { // act result := d.Command("ReadCounter")(map[string]interface{}{}) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], want) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, want, result.(map[string]interface{})["val"]) } func TestPCF8583CommandsWriteRAM(t *testing.T) { @@ -159,7 +159,7 @@ func TestPCF8583CommandsWriteRAM(t *testing.T) { // act result := d.Command("WriteRAM")(addressValue) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestPCF8583CommandsReadRAM(t *testing.T) { @@ -171,8 +171,8 @@ func TestPCF8583CommandsReadRAM(t *testing.T) { // act result := d.Command("ReadRAM")(address) // assert - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) - gobottest.Assert(t, result.(map[string]interface{})["val"], uint8(0)) + assert.Nil(t, result.(map[string]interface{})["err"]) + assert.Equal(t, uint8(0), result.(map[string]interface{})["val"]) } func TestPCF8583WriteTime(t *testing.T) { @@ -210,21 +210,21 @@ func TestPCF8583WriteTime(t *testing.T) { // act err := d.WriteTime(initDate) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.yearOffset, initDate.Year()) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 11) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[1], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[2], wantCtrlStop) - gobottest.Assert(t, a.written[3], wantReg1Val) - gobottest.Assert(t, a.written[4], wantReg2Val) - gobottest.Assert(t, a.written[5], wantReg3Val) - gobottest.Assert(t, a.written[6], wantReg4Val) - gobottest.Assert(t, a.written[7], wantReg5Val) - gobottest.Assert(t, a.written[8], wantReg6Val) - gobottest.Assert(t, a.written[9], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[10], wantCrtlStart) + assert.Nil(t, err) + assert.Equal(t, initDate.Year(), d.yearOffset) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 11, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[1]) + assert.Equal(t, wantCtrlStop, a.written[2]) + assert.Equal(t, wantReg1Val, a.written[3]) + assert.Equal(t, wantReg2Val, a.written[4]) + assert.Equal(t, wantReg3Val, a.written[5]) + assert.Equal(t, wantReg4Val, a.written[6]) + assert.Equal(t, wantReg5Val, a.written[7]) + assert.Equal(t, wantReg6Val, a.written[8]) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[9]) + assert.Equal(t, wantCrtlStart, a.written[10]) } func TestPCF8583WriteTimeNoTimeModeFails(t *testing.T) { @@ -246,11 +246,11 @@ func TestPCF8583WriteTimeNoTimeModeFails(t *testing.T) { // act err := d.WriteTime(time.Now()) // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "wrong mode 0x30"), true) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 1) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "wrong mode 0x30") + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCF8583ReadTime(t *testing.T) { @@ -292,11 +292,11 @@ func TestPCF8583ReadTime(t *testing.T) { // act got, err := d.ReadTime() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, got, want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, want, got) } func TestPCF8583ReadTimeNoTimeModeFails(t *testing.T) { @@ -318,12 +318,12 @@ func TestPCF8583ReadTimeNoTimeModeFails(t *testing.T) { // act got, err := d.ReadTime() // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "wrong mode 0x20"), true) - gobottest.Assert(t, got, time.Time{}) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 1) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "wrong mode 0x20") + assert.Equal(t, time.Time{}, got) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCF8583WriteCounter(t *testing.T) { @@ -357,17 +357,17 @@ func TestPCF8583WriteCounter(t *testing.T) { // act err := d.WriteCounter(initCount) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 8) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[1], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[2], wantCtrlStop) - gobottest.Assert(t, a.written[3], wantReg1Val) - gobottest.Assert(t, a.written[4], wantReg2Val) - gobottest.Assert(t, a.written[5], wantReg3Val) - gobottest.Assert(t, a.written[6], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[7], wantCtrlStart) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 8, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[1]) + assert.Equal(t, wantCtrlStop, a.written[2]) + assert.Equal(t, wantReg1Val, a.written[3]) + assert.Equal(t, wantReg2Val, a.written[4]) + assert.Equal(t, wantReg3Val, a.written[5]) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[6]) + assert.Equal(t, wantCtrlStart, a.written[7]) } func TestPCF8583WriteCounterNoCounterModeFails(t *testing.T) { @@ -389,11 +389,11 @@ func TestPCF8583WriteCounterNoCounterModeFails(t *testing.T) { // act err := d.WriteCounter(123) // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "wrong mode 0x10"), true) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 1) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "wrong mode 0x10") + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCF8583ReadCounter(t *testing.T) { @@ -430,11 +430,11 @@ func TestPCF8583ReadCounter(t *testing.T) { // act got, err := d.ReadCounter() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, got, want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, want, got) } func TestPCF8583ReadCounterNoCounterModeFails(t *testing.T) { @@ -456,12 +456,12 @@ func TestPCF8583ReadCounterNoCounterModeFails(t *testing.T) { // act got, err := d.ReadCounter() // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "wrong mode 0x30"), true) - gobottest.Assert(t, got, int32(0)) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, numCallsRead, 1) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "wrong mode 0x30") + assert.Equal(t, int32(0), got) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCF8583WriteRam(t *testing.T) { @@ -480,10 +480,10 @@ func TestPCF8583WriteRam(t *testing.T) { // act err := d.WriteRAM(wantRAMAddress-pcf8583RamOffset, wantRAMValue) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], wantRAMAddress) - gobottest.Assert(t, a.written[1], wantRAMValue) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, wantRAMAddress, a.written[0]) + assert.Equal(t, wantRAMValue, a.written[1]) } func TestPCF8583WriteRamAddressOverflowFails(t *testing.T) { @@ -493,9 +493,9 @@ func TestPCF8583WriteRamAddressOverflowFails(t *testing.T) { // act err := d.WriteRAM(uint8(0xF0), 15) // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "overflow 256"), true) - gobottest.Assert(t, len(a.written), 0) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "overflow 256") + assert.Equal(t, 0, len(a.written)) } func TestPCF8583ReadRam(t *testing.T) { @@ -521,11 +521,11 @@ func TestPCF8583ReadRam(t *testing.T) { // act got, err := d.ReadRAM(wantRAMAddress - pcf8583RamOffset) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, want) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], wantRAMAddress) - gobottest.Assert(t, numCallsRead, 1) + assert.Nil(t, err) + assert.Equal(t, want, got) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, wantRAMAddress, a.written[0]) + assert.Equal(t, 1, numCallsRead) } func TestPCF8583ReadRamAddressOverflowFails(t *testing.T) { @@ -545,11 +545,11 @@ func TestPCF8583ReadRamAddressOverflowFails(t *testing.T) { // act got, err := d.ReadRAM(uint8(0xF0)) // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "overflow 256"), true) - gobottest.Assert(t, got, uint8(0)) - gobottest.Assert(t, len(a.written), 0) - gobottest.Assert(t, numCallsRead, 0) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "overflow 256") + assert.Equal(t, uint8(0), got) + assert.Equal(t, 0, len(a.written)) + assert.Equal(t, 0, numCallsRead) } func TestPCF8583_initializeNoModeSwitch(t *testing.T) { @@ -572,10 +572,10 @@ func TestPCF8583_initializeNoModeSwitch(t *testing.T) { // act, assert - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) } func TestPCF8583_initializeWithModeSwitch(t *testing.T) { @@ -604,10 +604,10 @@ func TestPCF8583_initializeWithModeSwitch(t *testing.T) { // act, assert - initialize() must be called on Start() err := d.Start() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, numCallsRead, 1) - gobottest.Assert(t, len(a.written), 3) - gobottest.Assert(t, a.written[0], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[1], uint8(pcf8583Reg_CTRL)) - gobottest.Assert(t, a.written[2], uint8(wantReg0Val)) + assert.Nil(t, err) + assert.Equal(t, 1, numCallsRead) + assert.Equal(t, 3, len(a.written)) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[0]) + assert.Equal(t, uint8(pcf8583Reg_CTRL), a.written[1]) + assert.Equal(t, uint8(wantReg0Val), a.written[2]) } diff --git a/drivers/i2c/pcf8591_driver_test.go b/drivers/i2c/pcf8591_driver_test.go index d00f5de68..b12032ec3 100644 --- a/drivers/i2c/pcf8591_driver_test.go +++ b/drivers/i2c/pcf8591_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,25 +28,25 @@ func TestNewPCF8591Driver(t *testing.T) { if !ok { t.Errorf("NewPCF8591Driver() should have returned a *PCF8591Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "PCF8591"), true) - gobottest.Assert(t, d.defaultAddress, 0x48) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "PCF8591")) + assert.Equal(t, 0x48, d.defaultAddress) } func TestPCF8591Start(t *testing.T) { d := NewPCF8591Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestPCF8591Halt(t *testing.T) { d := NewPCF8591Driver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestPCF8591WithPCF8591With400kbitStabilization(t *testing.T) { d := NewPCF8591Driver(newI2cTestAdaptor(), WithPCF8591With400kbitStabilization(5, 6)) - gobottest.Assert(t, d.additionalReadWrite, uint8(5)) - gobottest.Assert(t, d.additionalRead, uint8(6)) + assert.Equal(t, uint8(5), d.additionalReadWrite) + assert.Equal(t, uint8(6), d.additionalRead) } func TestPCF8591AnalogReadSingle(t *testing.T) { @@ -78,11 +78,11 @@ func TestPCF8591AnalogReadSingle(t *testing.T) { // act got, err := d.AnalogRead(description) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], ctrlByteOn) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, got, want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, ctrlByteOn, a.written[0]) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, want, got) } func TestPCF8591AnalogReadDiff(t *testing.T) { @@ -120,11 +120,11 @@ func TestPCF8591AnalogReadDiff(t *testing.T) { // act got, err := d.AnalogRead(description) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], ctrlByteOn) - gobottest.Assert(t, numCallsRead, 2) - gobottest.Assert(t, got, want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, ctrlByteOn, a.written[0]) + assert.Equal(t, 2, numCallsRead) + assert.Equal(t, want, got) } func TestPCF8591AnalogWrite(t *testing.T) { @@ -146,10 +146,10 @@ func TestPCF8591AnalogWrite(t *testing.T) { // act err := d.AnalogWrite("", int(want)) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], ctrlByteOn) - gobottest.Assert(t, a.written[1], want) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, ctrlByteOn, a.written[0]) + assert.Equal(t, want, a.written[1]) } func TestPCF8591AnalogOutputState(t *testing.T) { @@ -171,8 +171,8 @@ func TestPCF8591AnalogOutputState(t *testing.T) { // act err := d.AnalogOutputState(bitState == 1) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], wantCtrlByteVal) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, wantCtrlByteVal, a.written[0]) } } diff --git a/drivers/i2c/sht2x_driver_test.go b/drivers/i2c/sht2x_driver_test.go index 2578c6757..1fb630b90 100644 --- a/drivers/i2c/sht2x_driver_test.go +++ b/drivers/i2c/sht2x_driver_test.go @@ -2,12 +2,11 @@ package i2c import ( "bytes" - "errors" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -29,26 +28,26 @@ func TestNewSHT2xDriver(t *testing.T) { if !ok { t.Errorf("NewSHT2xDriver() should have returned a *SHT2xDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "SHT2x"), true) - gobottest.Assert(t, d.defaultAddress, 0x40) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "SHT2x")) + assert.Equal(t, 0x40, d.defaultAddress) } func TestSHT2xOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". b := NewSHT2xDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, b.GetBusOrDefault(1), 2) + assert.Equal(t, 2, b.GetBusOrDefault(1)) } func TestSHT2xStart(t *testing.T) { d := NewSHT2xDriver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSHT2xHalt(t *testing.T) { d, _ := initTestSHT2xDriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestSHT2xReset(t *testing.T) { @@ -58,7 +57,7 @@ func TestSHT2xReset(t *testing.T) { } _ = d.Start() err := d.Reset() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSHT2xMeasurements(t *testing.T) { @@ -76,11 +75,11 @@ func TestSHT2xMeasurements(t *testing.T) { } _ = d.Start() temp, err := d.Temperature() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, temp, float32(18.809052)) + assert.Nil(t, err) + assert.Equal(t, float32(18.809052), temp) hum, err := d.Humidity() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, hum, float32(40.279907)) + assert.Nil(t, err) + assert.Equal(t, float32(40.279907), hum) } func TestSHT2xAccuracy(t *testing.T) { @@ -99,9 +98,9 @@ func TestSHT2xAccuracy(t *testing.T) { } _ = d.Start() _ = d.SetAccuracy(SHT2xAccuracyLow) - gobottest.Assert(t, d.Accuracy(), SHT2xAccuracyLow) + assert.Equal(t, SHT2xAccuracyLow, d.Accuracy()) err := d.sendAccuracy() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSHT2xTemperatureCrcError(t *testing.T) { @@ -117,8 +116,8 @@ func TestSHT2xTemperatureCrcError(t *testing.T) { return buf.Len(), nil } temp, err := d.Temperature() - gobottest.Assert(t, err, errors.New("Invalid crc")) - gobottest.Assert(t, temp, float32(0.0)) + assert.Errorf(t, err, "Invalid crc") + assert.Equal(t, float32(0.0), temp) } func TestSHT2xHumidityCrcError(t *testing.T) { @@ -134,8 +133,8 @@ func TestSHT2xHumidityCrcError(t *testing.T) { return buf.Len(), nil } hum, err := d.Humidity() - gobottest.Assert(t, err, errors.New("Invalid crc")) - gobottest.Assert(t, hum, float32(0.0)) + assert.Errorf(t, err, "Invalid crc") + assert.Equal(t, float32(0.0), hum) } func TestSHT2xTemperatureLengthError(t *testing.T) { @@ -151,8 +150,8 @@ func TestSHT2xTemperatureLengthError(t *testing.T) { return buf.Len(), nil } temp, err := d.Temperature() - gobottest.Assert(t, err, ErrNotEnoughBytes) - gobottest.Assert(t, temp, float32(0.0)) + assert.Equal(t, ErrNotEnoughBytes, err) + assert.Equal(t, float32(0.0), temp) } func TestSHT2xHumidityLengthError(t *testing.T) { @@ -168,6 +167,6 @@ func TestSHT2xHumidityLengthError(t *testing.T) { return buf.Len(), nil } hum, err := d.Humidity() - gobottest.Assert(t, err, ErrNotEnoughBytes) - gobottest.Assert(t, hum, float32(0.0)) + assert.Equal(t, ErrNotEnoughBytes, err) + assert.Equal(t, float32(0.0), hum) } diff --git a/drivers/i2c/sht3x_driver_test.go b/drivers/i2c/sht3x_driver_test.go index 522b66b9f..15a0e64bd 100644 --- a/drivers/i2c/sht3x_driver_test.go +++ b/drivers/i2c/sht3x_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -28,26 +28,26 @@ func TestNewSHT3xDriver(t *testing.T) { if !ok { t.Errorf("NewSHT3xDriver() should have returned a *SHT3xDriver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "SHT3x"), true) - gobottest.Assert(t, d.defaultAddress, 0x44) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "SHT3x")) + assert.Equal(t, 0x44, d.defaultAddress) } func TestSHT3xOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewSHT3xDriver(newI2cTestAdaptor(), WithBus(2)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) + assert.Equal(t, 2, d.GetBusOrDefault(1)) } func TestSHT3xStart(t *testing.T) { d := NewSHT3xDriver(newI2cTestAdaptor()) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSHT3xHalt(t *testing.T) { d, _ := initTestSHT3xDriverWithStubbedAdaptor() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestSHT3xSampleNormal(t *testing.T) { @@ -58,13 +58,13 @@ func TestSHT3xSampleNormal(t *testing.T) { } temp, rh, _ := d.Sample() - gobottest.Assert(t, temp, float32(85.523003)) - gobottest.Assert(t, rh, float32(74.5845)) + assert.Equal(t, float32(85.523003), temp) + assert.Equal(t, float32(74.5845), rh) // check the temp with the units in F d.Units = "F" temp, _, _ = d.Sample() - gobottest.Assert(t, temp, float32(185.9414)) + assert.Equal(t, float32(185.9414), temp) } func TestSHT3xSampleBadCrc(t *testing.T) { @@ -76,7 +76,7 @@ func TestSHT3xSampleBadCrc(t *testing.T) { } _, _, err := d.Sample() - gobottest.Assert(t, err, ErrInvalidCrc) + assert.Equal(t, ErrInvalidCrc, err) // Check that the 2nd crc failure is caught a.i2cReadImpl = func(b []byte) (int, error) { @@ -85,7 +85,7 @@ func TestSHT3xSampleBadCrc(t *testing.T) { } _, _, err = d.Sample() - gobottest.Assert(t, err, ErrInvalidCrc) + assert.Equal(t, ErrInvalidCrc, err) } func TestSHT3xSampleBadRead(t *testing.T) { @@ -97,7 +97,7 @@ func TestSHT3xSampleBadRead(t *testing.T) { } _, _, err := d.Sample() - gobottest.Assert(t, err, ErrNotEnoughBytes) + assert.Equal(t, ErrNotEnoughBytes, err) } func TestSHT3xSampleUnits(t *testing.T) { @@ -110,7 +110,7 @@ func TestSHT3xSampleUnits(t *testing.T) { d.Units = "K" _, _, err := d.Sample() - gobottest.Assert(t, err, ErrInvalidTemp) + assert.Equal(t, ErrInvalidTemp, err) } // Test internal sendCommandDelayGetResponse @@ -126,7 +126,7 @@ func TestSHT3xSCDGRIoFailures(t *testing.T) { } _, err := d.sendCommandDelayGetResponse(nil, nil, 2) - gobottest.Assert(t, err, ErrNotEnoughBytes) + assert.Equal(t, ErrNotEnoughBytes, err) // Don't read any bytes and return an error a.i2cReadImpl = func([]byte) (int, error) { @@ -134,7 +134,7 @@ func TestSHT3xSCDGRIoFailures(t *testing.T) { } _, err = d.sendCommandDelayGetResponse(nil, nil, 1) - gobottest.Assert(t, err, invalidRead) + assert.Equal(t, invalidRead, err) // Don't write any bytes and return an error a.i2cWriteImpl = func([]byte) (int, error) { @@ -142,7 +142,7 @@ func TestSHT3xSCDGRIoFailures(t *testing.T) { } _, err = d.sendCommandDelayGetResponse(nil, nil, 1) - gobottest.Assert(t, err, invalidWrite) + assert.Equal(t, invalidWrite, err) } // Test Heater and getStatusRegister @@ -155,8 +155,8 @@ func TestSHT3xHeater(t *testing.T) { } status, err := d.Heater() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, status, true) + assert.Nil(t, err) + assert.True(t, status) // heater disabled a.i2cReadImpl = func(b []byte) (int, error) { @@ -165,8 +165,8 @@ func TestSHT3xHeater(t *testing.T) { } status, err = d.Heater() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, status, false) + assert.Nil(t, err) + assert.False(t, status) // heater crc failed a.i2cReadImpl = func(b []byte) (int, error) { @@ -175,7 +175,7 @@ func TestSHT3xHeater(t *testing.T) { } _, err = d.Heater() - gobottest.Assert(t, err, ErrInvalidCrc) + assert.Equal(t, ErrInvalidCrc, err) // heater read failed a.i2cReadImpl = func(b []byte) (int, error) { @@ -184,7 +184,7 @@ func TestSHT3xHeater(t *testing.T) { } _, err = d.Heater() - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) } func TestSHT3xSetHeater(t *testing.T) { @@ -196,18 +196,18 @@ func TestSHT3xSetHeater(t *testing.T) { func TestSHT3xSetAccuracy(t *testing.T) { d, _ := initTestSHT3xDriverWithStubbedAdaptor() - gobottest.Assert(t, d.Accuracy(), byte(SHT3xAccuracyHigh)) + assert.Equal(t, byte(SHT3xAccuracyHigh), d.Accuracy()) err := d.SetAccuracy(SHT3xAccuracyMedium) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.Accuracy(), byte(SHT3xAccuracyMedium)) + assert.Nil(t, err) + assert.Equal(t, byte(SHT3xAccuracyMedium), d.Accuracy()) err = d.SetAccuracy(SHT3xAccuracyLow) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.Accuracy(), byte(SHT3xAccuracyLow)) + assert.Nil(t, err) + assert.Equal(t, byte(SHT3xAccuracyLow), d.Accuracy()) err = d.SetAccuracy(0xff) - gobottest.Assert(t, err, ErrInvalidAccuracy) + assert.Equal(t, ErrInvalidAccuracy, err) } func TestSHT3xSerialNumber(t *testing.T) { @@ -219,6 +219,6 @@ func TestSHT3xSerialNumber(t *testing.T) { sn, err := d.SerialNumber() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, sn, uint32(0x2000beef)) + assert.Nil(t, err) + assert.Equal(t, uint32(0x2000beef), sn) } diff --git a/drivers/i2c/ssd1306_driver_test.go b/drivers/i2c/ssd1306_driver_test.go index 420446a4b..b140a9e5a 100644 --- a/drivers/i2c/ssd1306_driver_test.go +++ b/drivers/i2c/ssd1306_driver_test.go @@ -1,15 +1,14 @@ package i2c import ( - "errors" "fmt" "image" "reflect" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -31,9 +30,9 @@ func TestNewSSD1306Driver(t *testing.T) { if !ok { t.Errorf("new should have returned a *SSD1306Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "SSD1306"), true) - gobottest.Assert(t, d.defaultAddress, 0x3c) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "SSD1306")) + assert.Equal(t, 0x3c, d.defaultAddress) } func TestSSD1306StartDefault(t *testing.T) { @@ -44,7 +43,7 @@ func TestSSD1306StartDefault(t *testing.T) { ) d := NewSSD1306Driver(newI2cTestAdaptor(), WithSSD1306DisplayWidth(width), WithSSD1306DisplayHeight(height), WithSSD1306ExternalVCC(externalVCC)) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSSD1306Start128x32(t *testing.T) { @@ -55,7 +54,7 @@ func TestSSD1306Start128x32(t *testing.T) { ) d := NewSSD1306Driver(newI2cTestAdaptor(), WithSSD1306DisplayWidth(width), WithSSD1306DisplayHeight(height), WithSSD1306ExternalVCC(externalVCC)) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSSD1306Start96x16(t *testing.T) { @@ -66,7 +65,7 @@ func TestSSD1306Start96x16(t *testing.T) { ) d := NewSSD1306Driver(newI2cTestAdaptor(), WithSSD1306DisplayWidth(width), WithSSD1306DisplayHeight(height), WithSSD1306ExternalVCC(externalVCC)) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSSD1306StartExternalVCC(t *testing.T) { @@ -77,7 +76,7 @@ func TestSSD1306StartExternalVCC(t *testing.T) { ) d := NewSSD1306Driver(newI2cTestAdaptor(), WithSSD1306DisplayWidth(width), WithSSD1306DisplayHeight(height), WithSSD1306ExternalVCC(externalVCC)) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSSD1306StartSizeError(t *testing.T) { @@ -88,35 +87,35 @@ func TestSSD1306StartSizeError(t *testing.T) { ) d := NewSSD1306Driver(newI2cTestAdaptor(), WithSSD1306DisplayWidth(width), WithSSD1306DisplayHeight(height), WithSSD1306ExternalVCC(externalVCC)) - gobottest.Assert(t, d.Start(), errors.New("128x54 resolution is unsupported, supported resolutions: 128x64, 128x32, 96x16")) + assert.Errorf(t, d.Start(), "128x54 resolution is unsupported, supported resolutions: 128x64, 128x32, 96x16") } func TestSSD1306Halt(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) - gobottest.Assert(t, s.Halt(), nil) + assert.Nil(t, s.Halt()) } func TestSSD1306Options(t *testing.T) { s := NewSSD1306Driver(newI2cTestAdaptor(), WithBus(2), WithSSD1306DisplayHeight(32), WithSSD1306DisplayWidth(128)) - gobottest.Assert(t, s.GetBusOrDefault(1), 2) - gobottest.Assert(t, s.displayHeight, 32) - gobottest.Assert(t, s.displayWidth, 128) + assert.Equal(t, 2, s.GetBusOrDefault(1)) + assert.Equal(t, 32, s.displayHeight) + assert.Equal(t, 128, s.displayWidth) } func TestSSD1306Display(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(96, 16, false) _ = s.Start() - gobottest.Assert(t, s.Display(), nil) + assert.Nil(t, s.Display()) } func TestSSD1306ShowImage(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) _ = s.Start() img := image.NewRGBA(image.Rect(0, 0, 640, 480)) - gobottest.Assert(t, s.ShowImage(img), errors.New("image must match display width and height: 128x64")) + assert.Errorf(t, s.ShowImage(img), "image must match display width and height: 128x64") img = image.NewRGBA(image.Rect(0, 0, 128, 64)) - gobottest.Assert(t, s.ShowImage(img), nil) + assert.Nil(t, s.ShowImage(img)) } func TestSSD1306Command(t *testing.T) { @@ -132,7 +131,7 @@ func TestSSD1306Command(t *testing.T) { return 0, nil } err := s.command(0xFF) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSSD1306Commands(t *testing.T) { @@ -148,7 +147,7 @@ func TestSSD1306Commands(t *testing.T) { return 0, nil } err := s.commands([]byte{0x00, 0xFF}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSSD1306On(t *testing.T) { @@ -164,7 +163,7 @@ func TestSSD1306On(t *testing.T) { return 0, nil } err := s.On() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSSD1306Off(t *testing.T) { @@ -180,7 +179,7 @@ func TestSSD1306Off(t *testing.T) { return 0, nil } err := s.Off() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } func TestSSD1306Reset(t *testing.T) { @@ -197,7 +196,7 @@ func TestSSD1306Reset(t *testing.T) { return 0, nil } err := s.Reset() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } // COMMANDS @@ -205,28 +204,28 @@ func TestSSD1306Reset(t *testing.T) { func TestSSD1306CommandsDisplay(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) result := s.Command("Display")(map[string]interface{}{}) - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestSSD1306CommandsOn(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) result := s.Command("On")(map[string]interface{}{}) - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestSSD1306CommandsOff(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) result := s.Command("Off")(map[string]interface{}{}) - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestSSD1306CommandsClear(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) result := s.Command("Clear")(map[string]interface{}{}) - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestSSD1306CommandsSetContrast(t *testing.T) { @@ -243,19 +242,19 @@ func TestSSD1306CommandsSetContrast(t *testing.T) { result := s.Command("SetContrast")(map[string]interface{}{ "contrast": byte(0x10), }) - gobottest.Assert(t, result.(map[string]interface{})["err"], nil) + assert.Nil(t, result.(map[string]interface{})["err"]) } func TestSSD1306CommandsSet(t *testing.T) { s, _ := initTestSSD1306DriverWithStubbedAdaptor(128, 64, false) - gobottest.Assert(t, s.buffer.buffer[0], byte(0)) + assert.Equal(t, byte(0), s.buffer.buffer[0]) s.Command("Set")(map[string]interface{}{ "x": int(0), "y": int(0), "c": int(1), }) - gobottest.Assert(t, s.buffer.buffer[0], byte(1)) + assert.Equal(t, byte(1), s.buffer.buffer[0]) } func TestDisplayBuffer(t *testing.T) { @@ -273,17 +272,17 @@ func TestDisplayBuffer(t *testing.T) { len(display.buffer), size) } - gobottest.Assert(t, display.buffer[0], byte(0)) - gobottest.Assert(t, display.buffer[1], byte(0)) + assert.Equal(t, byte(0), display.buffer[0]) + assert.Equal(t, byte(0), display.buffer[1]) display.SetPixel(0, 0, 1) display.SetPixel(1, 0, 1) display.SetPixel(2, 0, 1) display.SetPixel(0, 1, 1) - gobottest.Assert(t, display.buffer[0], byte(3)) - gobottest.Assert(t, display.buffer[1], byte(1)) + assert.Equal(t, byte(3), display.buffer[0]) + assert.Equal(t, byte(1), display.buffer[1]) display.SetPixel(0, 1, 0) - gobottest.Assert(t, display.buffer[0], byte(1)) - gobottest.Assert(t, display.buffer[1], byte(1)) + assert.Equal(t, byte(1), display.buffer[0]) + assert.Equal(t, byte(1), display.buffer[1]) } diff --git a/drivers/i2c/th02_driver_test.go b/drivers/i2c/th02_driver_test.go index 1276424c9..51a46c66e 100644 --- a/drivers/i2c/th02_driver_test.go +++ b/drivers/i2c/th02_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -29,17 +29,17 @@ func TestNewTH02Driver(t *testing.T) { if !ok { t.Errorf("NewTH02Driver() should have returned a *NewTH02Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "TH02"), true) - gobottest.Assert(t, d.defaultAddress, 0x40) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "TH02")) + assert.Equal(t, 0x40, d.defaultAddress) } func TestTH02Options(t *testing.T) { // This is a general test, that options are applied in constructor by using the common options. // Further tests for options can also be done by call of "WithOption(val)(d)". d := NewTH02Driver(newI2cTestAdaptor(), WithBus(2), WithAddress(0x42)) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.GetAddressOrDefault(0x33), 0x42) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.Equal(t, 0x42, d.GetAddressOrDefault(0x33)) } func TestTH02SetAccuracy(t *testing.T) { @@ -74,7 +74,7 @@ func TestTH02WithFastMode(t *testing.T) { // act WithTH02FastMode(tc.value)(d) // assert - gobottest.Assert(t, d.fastMode, tc.want) + assert.Equal(t, tc.want, d.fastMode) }) } } @@ -102,10 +102,10 @@ func TestTH02FastMode(t *testing.T) { // act got, err := d.FastMode() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x03)) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x03), a.written[0]) + assert.Equal(t, tc.want, got) }) } } @@ -130,11 +130,11 @@ func TestTH02SetHeater(t *testing.T) { // act err := d.SetHeater(tc.heater) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, d.heating, tc.heater) - gobottest.Assert(t, len(a.written), 2) - gobottest.Assert(t, a.written[0], uint8(0x03)) - gobottest.Assert(t, a.written[1], tc.want) + assert.Nil(t, err) + assert.Equal(t, tc.heater, d.heating) + assert.Equal(t, 2, len(a.written)) + assert.Equal(t, uint8(0x03), a.written[0]) + assert.Equal(t, tc.want, a.written[1]) }) } } @@ -162,10 +162,10 @@ func TestTH02Heater(t *testing.T) { // act got, err := d.Heater() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x03)) - gobottest.Assert(t, got, tc.want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x03), a.written[0]) + assert.Equal(t, tc.want, got) }) } } @@ -186,10 +186,10 @@ func TestTH02SerialNumber(t *testing.T) { // act sn, err := d.SerialNumber() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.written), 1) - gobottest.Assert(t, a.written[0], uint8(0x11)) - gobottest.Assert(t, sn, want) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.written)) + assert.Equal(t, uint8(0x11), a.written[0]) + assert.Equal(t, want, sn) } func TestTH02Sample(t *testing.T) { @@ -289,7 +289,7 @@ func TestTH02Sample(t *testing.T) { b[0] = byte(data >> 8) // first read MSB from register 0x01 b[1] = byte(data & 0xFF) // second read LSB from register 0x02 default: - gobottest.Assert(t, fmt.Sprintf("unexpected register %d", reg), "only register 0 and 1 expected") + assert.Equal(t, "only register 0 and 1 expected", fmt.Sprintf("unexpected register %d", reg)) return 0, nil } return len(b), nil @@ -297,9 +297,9 @@ func TestTH02Sample(t *testing.T) { // act temp, rh, err := d.Sample() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, rh, float32(tc.wantRH)) - gobottest.Assert(t, temp, float32(tc.wantT)) + assert.Nil(t, err) + assert.Equal(t, float32(tc.wantRH), rh) + assert.Equal(t, float32(tc.wantT), temp) }) } } @@ -415,8 +415,8 @@ func TestTH02_readData(t *testing.T) { // act got, err := d.waitAndReadData() // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, got, tc.rtn) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.rtn, got) }) } } @@ -485,7 +485,7 @@ func TestTH02_createConfig(t *testing.T) { d.fastMode = tc.fast d.heating = tc.heating got := d.createConfig(tc.meas, tc.readTemp) - gobottest.Assert(t, tc.want, got) + assert.Equal(t, got, tc.want) }) } } diff --git a/drivers/i2c/tsl2561_driver_test.go b/drivers/i2c/tsl2561_driver_test.go index 276c484fd..2c363b997 100644 --- a/drivers/i2c/tsl2561_driver_test.go +++ b/drivers/i2c/tsl2561_driver_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // this ensures that the implementation is based on i2c.Driver, which implements the gobot.Driver @@ -39,20 +39,20 @@ func TestNewTSL2561Driver(t *testing.T) { if !ok { t.Errorf("NewTSL2561Driver() should have returned a *TSL2561Driver") } - gobottest.Refute(t, d.Driver, nil) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "TSL2561"), true) - gobottest.Assert(t, d.defaultAddress, 0x39) - gobottest.Assert(t, d.autoGain, false) - gobottest.Assert(t, d.gain, TSL2561Gain(0)) - gobottest.Assert(t, d.integrationTime, TSL2561IntegrationTime(2)) + assert.NotNil(t, d.Driver) + assert.True(t, strings.HasPrefix(d.Name(), "TSL2561")) + assert.Equal(t, 0x39, d.defaultAddress) + assert.False(t, d.autoGain) + assert.Equal(t, TSL2561Gain(0), d.gain) + assert.Equal(t, TSL2561IntegrationTime(2), d.integrationTime) } func TestTSL2561DriverOptions(t *testing.T) { // This is a general test, that options are applied in constructor by using the common WithBus() option and // least one of this driver. Further tests for options can also be done by call of "WithOption(val)(d)". d := NewTSL2561Driver(newI2cTestAdaptor(), WithBus(2), WithTSL2561AutoGain) - gobottest.Assert(t, d.GetBusOrDefault(1), 2) - gobottest.Assert(t, d.autoGain, true) + assert.Equal(t, 2, d.GetBusOrDefault(1)) + assert.True(t, d.autoGain) } func TestTSL2561DriverStart(t *testing.T) { @@ -60,7 +60,7 @@ func TestTSL2561DriverStart(t *testing.T) { d := NewTSL2561Driver(a) a.i2cReadImpl = testIDReader - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestTSL2561DriverStartNotFound(t *testing.T) { @@ -72,12 +72,12 @@ func TestTSL2561DriverStartNotFound(t *testing.T) { copy(b, buf.Bytes()) return buf.Len(), nil } - gobottest.Assert(t, d.Start(), errors.New("TSL2561 device not found (0x1)")) + assert.Errorf(t, d.Start(), "TSL2561 device not found (0x1)") } func TestTSL2561DriverHalt(t *testing.T) { d, _ := initTestTSL2561Driver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestTSL2561DriverRead16(t *testing.T) { @@ -93,8 +93,8 @@ func TestTSL2561DriverRead16(t *testing.T) { return buf.Len(), nil } val, err := d.connection.ReadWordData(1) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, val, uint16(0xAEEA)) + assert.Nil(t, err) + assert.Equal(t, uint16(0xAEEA), val) } func TestTSL2561DriverValidOptions(t *testing.T) { @@ -105,9 +105,9 @@ func TestTSL2561DriverValidOptions(t *testing.T) { WithAddress(TSL2561AddressLow), WithTSL2561AutoGain) - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.autoGain, true) - gobottest.Assert(t, d.integrationTime, TSL2561IntegrationTime101MS) + assert.NotNil(t, d) + assert.True(t, d.autoGain) + assert.Equal(t, TSL2561IntegrationTime101MS, d.integrationTime) } func TestTSL2561DriverMoreOptions(t *testing.T) { @@ -118,9 +118,9 @@ func TestTSL2561DriverMoreOptions(t *testing.T) { WithAddress(TSL2561AddressLow), WithTSL2561Gain16X) - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.autoGain, false) - gobottest.Assert(t, d.gain, TSL2561Gain(TSL2561Gain16X)) + assert.NotNil(t, d) + assert.False(t, d.autoGain) + assert.Equal(t, TSL2561Gain(TSL2561Gain16X), d.gain) } func TestTSL2561DriverEvenMoreOptions(t *testing.T) { @@ -131,10 +131,10 @@ func TestTSL2561DriverEvenMoreOptions(t *testing.T) { WithAddress(TSL2561AddressLow), WithTSL2561Gain1X) - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.autoGain, false) - gobottest.Assert(t, d.gain, TSL2561Gain(TSL2561Gain1X)) - gobottest.Assert(t, d.integrationTime, TSL2561IntegrationTime13MS) + assert.NotNil(t, d) + assert.False(t, d.autoGain) + assert.Equal(t, TSL2561Gain(TSL2561Gain1X), d.gain) + assert.Equal(t, TSL2561IntegrationTime13MS, d.integrationTime) } func TestTSL2561DriverYetEvenMoreOptions(t *testing.T) { @@ -145,9 +145,9 @@ func TestTSL2561DriverYetEvenMoreOptions(t *testing.T) { WithAddress(TSL2561AddressLow), WithTSL2561AutoGain) - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.autoGain, true) - gobottest.Assert(t, d.integrationTime, TSL2561IntegrationTime402MS) + assert.NotNil(t, d) + assert.True(t, d.autoGain) + assert.Equal(t, TSL2561IntegrationTime402MS, d.integrationTime) } func TestTSL2561DriverGetDataWriteError(t *testing.T) { @@ -157,7 +157,7 @@ func TestTSL2561DriverGetDataWriteError(t *testing.T) { } _, _, err := d.getData() - gobottest.Assert(t, err, errors.New("write error")) + assert.Errorf(t, err, "write error") } func TestTSL2561DriverGetDataReadError(t *testing.T) { @@ -167,7 +167,7 @@ func TestTSL2561DriverGetDataReadError(t *testing.T) { } _, _, err := d.getData() - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } func TestTSL2561DriverGetLuminocity(t *testing.T) { @@ -180,10 +180,10 @@ func TestTSL2561DriverGetLuminocity(t *testing.T) { return buf.Len(), nil } bb, ir, err := d.GetLuminocity() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, bb, uint16(12365)) - gobottest.Assert(t, ir, uint16(12365)) - gobottest.Assert(t, d.CalculateLux(bb, ir), uint32(72)) + assert.Nil(t, err) + assert.Equal(t, uint16(12365), bb) + assert.Equal(t, uint16(12365), ir) + assert.Equal(t, uint32(72), d.CalculateLux(bb, ir)) } func TestTSL2561DriverGetLuminocityAutoGain(t *testing.T) { @@ -202,10 +202,10 @@ func TestTSL2561DriverGetLuminocityAutoGain(t *testing.T) { _ = d.Start() bb, ir, err := d.GetLuminocity() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, bb, uint16(12365)) - gobottest.Assert(t, ir, uint16(12365)) - gobottest.Assert(t, d.CalculateLux(bb, ir), uint32(72)) + assert.Nil(t, err) + assert.Equal(t, uint16(12365), bb) + assert.Equal(t, uint16(12365), ir) + assert.Equal(t, uint32(72), d.CalculateLux(bb, ir)) } func TestTSL2561SetIntegrationTimeError(t *testing.T) { @@ -213,7 +213,7 @@ func TestTSL2561SetIntegrationTimeError(t *testing.T) { a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.SetIntegrationTime(TSL2561IntegrationTime101MS), errors.New("write error")) + assert.Errorf(t, d.SetIntegrationTime(TSL2561IntegrationTime101MS), "write error") } func TestTSL2561SetGainError(t *testing.T) { @@ -221,7 +221,7 @@ func TestTSL2561SetGainError(t *testing.T) { a.i2cWriteImpl = func([]byte) (int, error) { return 0, errors.New("write error") } - gobottest.Assert(t, d.SetGain(TSL2561Gain16X), errors.New("write error")) + assert.Errorf(t, d.SetGain(TSL2561Gain16X), "write error") } func TestTSL2561getHiLo13MS(t *testing.T) { @@ -231,8 +231,8 @@ func TestTSL2561getHiLo13MS(t *testing.T) { WithTSL2561AutoGain) hi, lo := d.getHiLo() - gobottest.Assert(t, hi, uint16(tsl2561AgcTHi13MS)) - gobottest.Assert(t, lo, uint16(tsl2561AgcTLo13MS)) + assert.Equal(t, uint16(tsl2561AgcTHi13MS), hi) + assert.Equal(t, uint16(tsl2561AgcTLo13MS), lo) } func TestTSL2561getHiLo101MS(t *testing.T) { @@ -242,8 +242,8 @@ func TestTSL2561getHiLo101MS(t *testing.T) { WithTSL2561AutoGain) hi, lo := d.getHiLo() - gobottest.Assert(t, hi, uint16(tsl2561AgcTHi101MS)) - gobottest.Assert(t, lo, uint16(tsl2561AgcTLo101MS)) + assert.Equal(t, uint16(tsl2561AgcTHi101MS), hi) + assert.Equal(t, uint16(tsl2561AgcTLo101MS), lo) } func TestTSL2561getHiLo402MS(t *testing.T) { @@ -253,8 +253,8 @@ func TestTSL2561getHiLo402MS(t *testing.T) { WithTSL2561AutoGain) hi, lo := d.getHiLo() - gobottest.Assert(t, hi, uint16(tsl2561AgcTHi402MS)) - gobottest.Assert(t, lo, uint16(tsl2561AgcTLo402MS)) + assert.Equal(t, uint16(tsl2561AgcTHi402MS), hi) + assert.Equal(t, uint16(tsl2561AgcTLo402MS), lo) } func TestTSL2561getClipScaling13MS(t *testing.T) { @@ -265,8 +265,8 @@ func TestTSL2561getClipScaling13MS(t *testing.T) { c, s := d.getClipScaling() d.waitForADC() - gobottest.Assert(t, c, uint16(tsl2561Clipping13MS)) - gobottest.Assert(t, s, uint32(tsl2561LuxCHScaleTInt0)) + assert.Equal(t, uint16(tsl2561Clipping13MS), c) + assert.Equal(t, uint32(tsl2561LuxCHScaleTInt0), s) } func TestTSL2561getClipScaling101MS(t *testing.T) { @@ -277,8 +277,8 @@ func TestTSL2561getClipScaling101MS(t *testing.T) { c, s := d.getClipScaling() d.waitForADC() - gobottest.Assert(t, c, uint16(tsl2561Clipping101MS)) - gobottest.Assert(t, s, uint32(tsl2561LuxChScaleTInt1)) + assert.Equal(t, uint16(tsl2561Clipping101MS), c) + assert.Equal(t, uint32(tsl2561LuxChScaleTInt1), s) } func TestTSL2561getClipScaling402MS(t *testing.T) { @@ -289,8 +289,8 @@ func TestTSL2561getClipScaling402MS(t *testing.T) { c, s := d.getClipScaling() d.waitForADC() - gobottest.Assert(t, c, uint16(tsl2561Clipping402MS)) - gobottest.Assert(t, s, uint32(1<>8)) + assert.Nil(t, err) + assert.Equal(t, 3, len(brd.i2cWritten)) + assert.Equal(t, reg, brd.i2cWritten[0]) + assert.Equal(t, uint8(val&0x00FF), brd.i2cWritten[1]) + assert.Equal(t, uint8(val>>8), brd.i2cWritten[2]) } func TestWriteBlockData(t *testing.T) { @@ -229,19 +228,19 @@ func TestWriteBlockData(t *testing.T) { // act err := con.WriteBlockData(reg, val) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(brd.i2cWritten), 33) - gobottest.Assert(t, brd.i2cWritten[0], reg) - gobottest.Assert(t, brd.i2cWritten[1:], val[0:32]) + assert.Nil(t, err) + assert.Equal(t, 33, len(brd.i2cWritten)) + assert.Equal(t, reg, brd.i2cWritten[0]) + assert.Equal(t, val[0:32], brd.i2cWritten[1:]) } func TestDefaultBus(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 0) + assert.Equal(t, 0, a.DefaultI2cBus()) } func TestGetI2cConnectionInvalidBus(t *testing.T) { a := NewAdaptor() _, err := a.GetI2cConnection(0x01, 99) - gobottest.Assert(t, err, errors.New("Invalid bus number 99, only 0 is supported")) + assert.Errorf(t, err, "Invalid bus number 99, only 0 is supported") } diff --git a/platforms/firmata/tcp_firmata_adaptor_test.go b/platforms/firmata/tcp_firmata_adaptor_test.go index 74b26b8df..71829d16b 100644 --- a/platforms/firmata/tcp_firmata_adaptor_test.go +++ b/platforms/firmata/tcp_firmata_adaptor_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*TCPAdaptor)(nil) @@ -17,5 +17,5 @@ func initTestTCPAdaptor() *TCPAdaptor { func TestFirmataTCPAdaptor(t *testing.T) { a := initTestTCPAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "TCPFirmata"), true) + assert.True(t, strings.HasPrefix(a.Name(), "TCPFirmata")) } diff --git a/platforms/holystone/hs200/hs200_driver_test.go b/platforms/holystone/hs200/hs200_driver_test.go index c63aedc87..42519a829 100644 --- a/platforms/holystone/hs200/hs200_driver_test.go +++ b/platforms/holystone/hs200/hs200_driver_test.go @@ -3,8 +3,8 @@ package hs200 import ( "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -12,6 +12,6 @@ var _ gobot.Driver = (*Driver)(nil) func TestHS200Driver(t *testing.T) { d := NewDriver("127.0.0.1:8080", "127.0.0.1:9090") - gobottest.Assert(t, d.tcpaddress, "127.0.0.1:8080") - gobottest.Assert(t, d.udpaddress, "127.0.0.1:9090") + assert.Equal(t, "127.0.0.1:8080", d.tcpaddress) + assert.Equal(t, "127.0.0.1:9090", d.udpaddress) } diff --git a/platforms/intel-iot/curie/imu_driver_test.go b/platforms/intel-iot/curie/imu_driver_test.go index 845604931..48723d230 100644 --- a/platforms/intel-iot/curie/imu_driver_test.go +++ b/platforms/intel-iot/curie/imu_driver_test.go @@ -2,13 +2,12 @@ package curie import ( "bytes" - "errors" "io" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/platforms/firmata" "gobot.io/x/gobot/v2/platforms/firmata/client" @@ -89,144 +88,144 @@ func initTestIMUDriver() *IMUDriver { func TestIMUDriverStart(t *testing.T) { d := initTestIMUDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestIMUDriverHalt(t *testing.T) { d := initTestIMUDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestIMUDriverDefaultName(t *testing.T) { d := initTestIMUDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "CurieIMU"), true) + assert.True(t, strings.HasPrefix(d.Name(), "CurieIMU")) } func TestIMUDriverSetName(t *testing.T) { d := initTestIMUDriver() d.SetName("mybot") - gobottest.Assert(t, d.Name(), "mybot") + assert.Equal(t, "mybot", d.Name()) } func TestIMUDriverConnection(t *testing.T) { d := initTestIMUDriver() - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) } func TestIMUDriverReadAccelerometer(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.ReadAccelerometer(), nil) + assert.Nil(t, d.ReadAccelerometer()) } func TestIMUDriverReadAccelerometerData(t *testing.T) { _, err := parseAccelerometerData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseAccelerometerData([]byte{0xF0, 0x11, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, &AccelerometerData{X: 1920, Y: 1920, Z: 1920}) + assert.Nil(t, err) + assert.Equal(t, &AccelerometerData{X: 1920, Y: 1920, Z: 1920}, result) } func TestIMUDriverReadGyroscope(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.ReadGyroscope(), nil) + assert.Nil(t, d.ReadGyroscope()) } func TestIMUDriverReadGyroscopeData(t *testing.T) { _, err := parseGyroscopeData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseGyroscopeData([]byte{0xF0, 0x11, 0x01, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, &GyroscopeData{X: 1920, Y: 1920, Z: 1920}) + assert.Nil(t, err) + assert.Equal(t, &GyroscopeData{X: 1920, Y: 1920, Z: 1920}, result) } func TestIMUDriverReadTemperature(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.ReadTemperature(), nil) + assert.Nil(t, d.ReadTemperature()) } func TestIMUDriverReadTemperatureData(t *testing.T) { _, err := parseTemperatureData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseTemperatureData([]byte{0xF0, 0x11, 0x02, 0x00, 0x02, 0x03, 0x04, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, float32(31.546875)) + assert.Nil(t, err) + assert.Equal(t, float32(31.546875), result) } func TestIMUDriverEnableShockDetection(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.EnableShockDetection(true), nil) + assert.Nil(t, d.EnableShockDetection(true)) } func TestIMUDriverShockDetectData(t *testing.T) { _, err := parseShockData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseShockData([]byte{0xF0, 0x11, 0x03, 0x00, 0x02, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, &ShockData{Axis: 0, Direction: 2}) + assert.Nil(t, err) + assert.Equal(t, &ShockData{Axis: 0, Direction: 2}, result) } func TestIMUDriverEnableStepCounter(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.EnableStepCounter(true), nil) + assert.Nil(t, d.EnableStepCounter(true)) } func TestIMUDriverStepCountData(t *testing.T) { _, err := parseStepData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseStepData([]byte{0xF0, 0x11, 0x04, 0x00, 0x02, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, int16(256)) + assert.Nil(t, err) + assert.Equal(t, int16(256), result) } func TestIMUDriverEnableTapDetection(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.EnableTapDetection(true), nil) + assert.Nil(t, d.EnableTapDetection(true)) } func TestIMUDriverTapDetectData(t *testing.T) { _, err := parseTapData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseTapData([]byte{0xF0, 0x11, 0x05, 0x00, 0x02, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, &TapData{Axis: 0, Direction: 2}) + assert.Nil(t, err) + assert.Equal(t, &TapData{Axis: 0, Direction: 2}, result) } func TestIMUDriverEnableReadMotion(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.ReadMotion(), nil) + assert.Nil(t, d.ReadMotion()) } func TestIMUDriverReadMotionData(t *testing.T) { _, err := parseMotionData([]byte{}) - gobottest.Assert(t, err, errors.New("Invalid data")) + assert.Errorf(t, err, "Invalid data") result, err := parseMotionData([]byte{0xF0, 0x11, 0x06, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, result, &MotionData{AX: 1920, AY: 1920, AZ: 1920, GX: 1920, GY: 1920, GZ: 1920}) + assert.Nil(t, err) + assert.Equal(t, &MotionData{AX: 1920, AY: 1920, AZ: 1920, GX: 1920, GY: 1920, GZ: 1920}, result) } func TestIMUDriverHandleEvents(t *testing.T) { d := initTestIMUDriver() _ = d.Start() - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x01, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x02, 0x00, 0x02, 0x03, 0x04, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x03, 0x00, 0x02, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x04, 0x00, 0x02, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x05, 0x00, 0x02, 0xf7}), nil) - gobottest.Assert(t, d.handleEvent([]byte{0xF0, 0x11, 0x06, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7}), nil) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x01, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x02, 0x00, 0x02, 0x03, 0x04, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x03, 0x00, 0x02, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x04, 0x00, 0x02, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x05, 0x00, 0x02, 0xf7})) + assert.Nil(t, d.handleEvent([]byte{0xF0, 0x11, 0x06, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0xf7})) } diff --git a/platforms/intel-iot/edison/edison_adaptor_test.go b/platforms/intel-iot/edison/edison_adaptor_test.go index 68baab0d7..79e557e7a 100644 --- a/platforms/intel-iot/edison/edison_adaptor_test.go +++ b/platforms/intel-iot/edison/edison_adaptor_test.go @@ -5,11 +5,11 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/aio" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -223,17 +223,17 @@ func initTestAdaptorWithMockedFilesystem(boardType string) (*Adaptor, *system.Mo func TestName(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Edison"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Edison")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestConnect(t *testing.T) { a, _ := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.DefaultI2cBus(), 6) - gobottest.Assert(t, a.board, "arduino") - gobottest.Assert(t, a.Connect(), nil) + assert.Equal(t, 6, a.DefaultI2cBus()) + assert.Equal(t, "arduino", a.board) + assert.Nil(t, a.Connect()) } func TestArduinoSetupFail263(t *testing.T) { @@ -241,7 +241,7 @@ func TestArduinoSetupFail263(t *testing.T) { delete(fs.Files, "/sys/class/gpio/gpio263/direction") err := a.arduinoSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio263/direction: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/gpio/gpio263/direction: no such file") } func TestArduinoSetupFail240(t *testing.T) { @@ -249,7 +249,7 @@ func TestArduinoSetupFail240(t *testing.T) { delete(fs.Files, "/sys/class/gpio/gpio240/direction") err := a.arduinoSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio240/direction: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/gpio/gpio240/direction: no such file") } func TestArduinoSetupFail111(t *testing.T) { @@ -257,7 +257,7 @@ func TestArduinoSetupFail111(t *testing.T) { delete(fs.Files, "/sys/kernel/debug/gpio_debug/gpio111/current_pinmux") err := a.arduinoSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/kernel/debug/gpio_debug/gpio111/current_pinmux: no such file"), true) + assert.Contains(t, err.Error(), "/sys/kernel/debug/gpio_debug/gpio111/current_pinmux: no such file") } func TestArduinoSetupFail131(t *testing.T) { @@ -265,56 +265,56 @@ func TestArduinoSetupFail131(t *testing.T) { delete(fs.Files, "/sys/kernel/debug/gpio_debug/gpio131/current_pinmux") err := a.arduinoSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/kernel/debug/gpio_debug/gpio131/current_pinmux: no such file"), true) + assert.Contains(t, err.Error(), "/sys/kernel/debug/gpio_debug/gpio131/current_pinmux: no such file") } func TestArduinoI2CSetupFailTristate(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.arduinoSetup(), nil) + assert.Nil(t, a.arduinoSetup()) fs.WithWriteError = true err := a.arduinoI2CSetup() - gobottest.Assert(t, err, fmt.Errorf("write error")) + assert.Errorf(t, err, "write error") } func TestArduinoI2CSetupFail14(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.arduinoSetup(), nil) + assert.Nil(t, a.arduinoSetup()) delete(fs.Files, "/sys/class/gpio/gpio14/direction") err := a.arduinoI2CSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio14/direction: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/gpio/gpio14/direction: no such file") } func TestArduinoI2CSetupUnexportFail(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.arduinoSetup(), nil) + assert.Nil(t, a.arduinoSetup()) delete(fs.Files, "/sys/class/gpio/unexport") err := a.arduinoI2CSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/unexport: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/gpio/unexport: no such file") } func TestArduinoI2CSetupFail236(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.arduinoSetup(), nil) + assert.Nil(t, a.arduinoSetup()) delete(fs.Files, "/sys/class/gpio/gpio236/direction") err := a.arduinoI2CSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/gpio236/direction: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/gpio/gpio236/direction: no such file") } func TestArduinoI2CSetupFail28(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") - gobottest.Assert(t, a.arduinoSetup(), nil) + assert.Nil(t, a.arduinoSetup()) delete(fs.Files, "/sys/kernel/debug/gpio_debug/gpio28/current_pinmux") err := a.arduinoI2CSetup() - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/kernel/debug/gpio_debug/gpio28/current_pinmux: no such file"), true) + assert.Contains(t, err.Error(), "/sys/kernel/debug/gpio_debug/gpio28/current_pinmux: no such file") } func TestConnectArduinoError(t *testing.T) { @@ -322,7 +322,7 @@ func TestConnectArduinoError(t *testing.T) { fs.WithWriteError = true err := a.Connect() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestConnectArduinoWriteError(t *testing.T) { @@ -330,30 +330,30 @@ func TestConnectArduinoWriteError(t *testing.T) { fs.WithWriteError = true err := a.Connect() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestConnectSparkfun(t *testing.T) { a, _ := initTestAdaptorWithMockedFilesystem("sparkfun") - gobottest.Assert(t, a.Connect(), nil) - gobottest.Assert(t, a.DefaultI2cBus(), 1) - gobottest.Assert(t, a.board, "sparkfun") + assert.Nil(t, a.Connect()) + assert.Equal(t, 1, a.DefaultI2cBus()) + assert.Equal(t, "sparkfun", a.board) } func TestConnectMiniboard(t *testing.T) { a, _ := initTestAdaptorWithMockedFilesystem("miniboard") - gobottest.Assert(t, a.Connect(), nil) - gobottest.Assert(t, a.DefaultI2cBus(), 1) - gobottest.Assert(t, a.board, "miniboard") + assert.Nil(t, a.Connect()) + assert.Equal(t, 1, a.DefaultI2cBus()) + assert.Equal(t, "miniboard", a.board) } func TestConnectUnknown(t *testing.T) { a := NewAdaptor("wha") err := a.Connect() - gobottest.Assert(t, strings.Contains(err.Error(), "Unknown board type: wha"), true) + assert.Contains(t, err.Error(), "Unknown board type: wha") } func TestFinalize(t *testing.T) { @@ -363,18 +363,18 @@ func TestFinalize(t *testing.T) { _ = a.PwmWrite("5", 100) _, _ = a.GetI2cConnection(0xff, 6) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) // assert that finalize after finalize is working - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) // assert that re-connect is working _ = a.Connect() // remove one file to force Finalize error delete(fs.Files, "/sys/class/gpio/unexport") err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "1 error occurred"), true) - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/unexport"), true) + assert.Contains(t, err.Error(), "1 error occurred") + assert.Contains(t, err.Error(), "/sys/class/gpio/unexport") } func TestFinalizeError(t *testing.T) { @@ -384,22 +384,22 @@ func TestFinalizeError(t *testing.T) { fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "6 errors occurred"), true) - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) - gobottest.Assert(t, strings.Contains(err.Error(), "SetEnabled(false) failed for id 1 with write error"), true) - gobottest.Assert(t, strings.Contains(err.Error(), "Unexport() failed for id 1 with write error"), true) + assert.Contains(t, err.Error(), "6 errors occurred") + assert.Contains(t, err.Error(), "write error") + assert.Contains(t, err.Error(), "SetEnabled(false) failed for id 1 with write error") + assert.Contains(t, err.Error(), "Unexport() failed for id 1 with write error") } func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") _ = a.DigitalWrite("13", 1) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio40/value"].Contents, "1") + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio40/value"].Contents) _ = a.DigitalWrite("2", 0) i, err := a.DigitalRead("2") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, i, 0) + assert.Nil(t, err) + assert.Equal(t, 0, i) } func TestDigitalPinInFileError(t *testing.T) { @@ -410,7 +410,7 @@ func TestDigitalPinInFileError(t *testing.T) { _ = a.Connect() _, err := a.DigitalPin("13") - gobottest.Assert(t, strings.Contains(err.Error(), "no such file"), true) + assert.Contains(t, err.Error(), "no such file") } @@ -422,7 +422,7 @@ func TestDigitalPinInResistorFileError(t *testing.T) { _ = a.Connect() _, err := a.DigitalPin("13") - gobottest.Assert(t, strings.Contains(err.Error(), "no such file"), true) + assert.Contains(t, err.Error(), "no such file") } func TestDigitalPinInLevelShifterFileError(t *testing.T) { @@ -433,7 +433,7 @@ func TestDigitalPinInLevelShifterFileError(t *testing.T) { _ = a.Connect() _, err := a.DigitalPin("13") - gobottest.Assert(t, strings.Contains(err.Error(), "no such file"), true) + assert.Contains(t, err.Error(), "no such file") } func TestDigitalPinInMuxFileError(t *testing.T) { @@ -444,7 +444,7 @@ func TestDigitalPinInMuxFileError(t *testing.T) { _ = a.Connect() _, err := a.DigitalPin("13") - gobottest.Assert(t, strings.Contains(err.Error(), "no such file"), true) + assert.Contains(t, err.Error(), "no such file") } func TestDigitalWriteError(t *testing.T) { @@ -452,7 +452,7 @@ func TestDigitalWriteError(t *testing.T) { fs.WithWriteError = true err := a.DigitalWrite("13", 1) - gobottest.Assert(t, err, fmt.Errorf("write error")) + assert.Errorf(t, err, "write error") } func TestDigitalReadWriteError(t *testing.T) { @@ -460,18 +460,18 @@ func TestDigitalReadWriteError(t *testing.T) { fs.WithWriteError = true _, err := a.DigitalRead("13") - gobottest.Assert(t, err, fmt.Errorf("write error")) + assert.Errorf(t, err, "write error") } func TestPwm(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem("arduino") err := a.PwmWrite("5", 100) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm1/duty_cycle"].Contents, "1960") + assert.Nil(t, err) + assert.Equal(t, "1960", fs.Files["/sys/class/pwm/pwmchip0/pwm1/duty_cycle"].Contents) err = a.PwmWrite("7", 100) - gobottest.Assert(t, err, fmt.Errorf("'7' is not a valid id for a PWM pin")) + assert.Errorf(t, err, "'7' is not a valid id for a PWM pin") } func TestPwmExportError(t *testing.T) { @@ -479,10 +479,10 @@ func TestPwmExportError(t *testing.T) { fs := a.sys.UseMockFilesystem(pwmMockPathsMux13Arduino) delete(fs.Files, "/sys/class/pwm/pwmchip0/export") err := a.Connect() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) err = a.PwmWrite("5", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/export: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/pwm/pwmchip0/export: no such file") } func TestPwmEnableError(t *testing.T) { @@ -492,7 +492,7 @@ func TestPwmEnableError(t *testing.T) { _ = a.Connect() err := a.PwmWrite("5", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/pwm1/enable: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/pwm/pwmchip0/pwm1/enable: no such file") } func TestPwmWritePinError(t *testing.T) { @@ -500,7 +500,7 @@ func TestPwmWritePinError(t *testing.T) { fs.WithWriteError = true err := a.PwmWrite("5", 100) - gobottest.Assert(t, err, fmt.Errorf("write error")) + assert.Errorf(t, err, "write error") } func TestPwmWriteError(t *testing.T) { @@ -508,7 +508,7 @@ func TestPwmWriteError(t *testing.T) { fs.WithWriteError = true err := a.PwmWrite("5", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestPwmReadError(t *testing.T) { @@ -516,7 +516,7 @@ func TestPwmReadError(t *testing.T) { fs.WithReadError = true err := a.PwmWrite("5", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "read error"), true) + assert.Contains(t, err.Error(), "read error") } func TestAnalog(t *testing.T) { @@ -524,7 +524,7 @@ func TestAnalog(t *testing.T) { fs.Files["/sys/bus/iio/devices/iio:device1/in_voltage0_raw"].Contents = "1000\n" i, _ := a.AnalogRead("0") - gobottest.Assert(t, i, 250) + assert.Equal(t, 250, i) } func TestAnalogError(t *testing.T) { @@ -532,7 +532,7 @@ func TestAnalogError(t *testing.T) { fs.WithReadError = true _, err := a.AnalogRead("0") - gobottest.Assert(t, err, fmt.Errorf("read error")) + assert.Errorf(t, err, "read error") } func TestI2cWorkflow(t *testing.T) { @@ -540,17 +540,17 @@ func TestI2cWorkflow(t *testing.T) { a.sys.UseMockSyscall() con, err := a.GetI2cConnection(0xff, 6) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0x00, 0x01}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) data := []byte{42, 42} _, err = con.Read(data) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, data, []byte{0x00, 0x01}) + assert.Nil(t, err) + assert.Equal(t, []byte{0x00, 0x01}, data) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -558,17 +558,17 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem(pwmMockPathsMux13ArduinoI2c) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 6) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0x0A}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Refute(t, err, nil) - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.NotNil(t, err) + assert.Contains(t, err.Error(), "close error") } @@ -613,7 +613,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateAndSetupI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } diff --git a/platforms/intel-iot/joule/joule_adaptor_test.go b/platforms/intel-iot/joule/joule_adaptor_test.go index 43771dc06..316a1da0d 100644 --- a/platforms/intel-iot/joule/joule_adaptor_test.go +++ b/platforms/intel-iot/joule/joule_adaptor_test.go @@ -1,15 +1,14 @@ package joule import ( - "errors" "fmt" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -99,9 +98,9 @@ func initTestAdaptorWithMockedFilesystem() (*Adaptor, *system.MockFilesystem) { func TestName(t *testing.T) { a, _ := initTestAdaptorWithMockedFilesystem() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Joule"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Joule")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestFinalize(t *testing.T) { @@ -110,43 +109,43 @@ func TestFinalize(t *testing.T) { _ = a.DigitalWrite("J12_1", 1) _ = a.PwmWrite("J12_26", 100) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) // assert finalize after finalize is working - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) // assert re-connect is working - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) } func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem() _ = a.DigitalWrite("J12_1", 1) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio451/value"].Contents, "1") + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio451/value"].Contents) _ = a.DigitalWrite("J12_1", 0) i, err := a.DigitalRead("J12_1") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, i, 0) + assert.Nil(t, err) + assert.Equal(t, 0, i) _, err = a.DigitalRead("P9_99") - gobottest.Assert(t, err, errors.New("'P9_99' is not a valid id for a digital pin")) + assert.Errorf(t, err, "'P9_99' is not a valid id for a digital pin") } func TestPwm(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem() err := a.PwmWrite("J12_26", 100) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents, "3921568") + assert.Nil(t, err) + assert.Equal(t, "3921568", fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents) err = a.PwmWrite("4", 100) - gobottest.Assert(t, err, errors.New("'4' is not a valid id for a pin")) + assert.Errorf(t, err, "'4' is not a valid id for a pin") err = a.PwmWrite("J12_1", 100) - gobottest.Assert(t, err, errors.New("'J12_1' is not a valid id for a PWM pin")) + assert.Errorf(t, err, "'J12_1' is not a valid id for a PWM pin") } func TestPwmPinExportError(t *testing.T) { @@ -154,7 +153,7 @@ func TestPwmPinExportError(t *testing.T) { delete(fs.Files, "/sys/class/pwm/pwmchip0/export") err := a.PwmWrite("J12_26", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/export: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/pwm/pwmchip0/export: no such file") } func TestPwmPinEnableError(t *testing.T) { @@ -162,12 +161,12 @@ func TestPwmPinEnableError(t *testing.T) { delete(fs.Files, "/sys/class/pwm/pwmchip0/pwm0/enable") err := a.PwmWrite("J12_26", 100) - gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/pwm0/enable: no such file"), true) + assert.Contains(t, err.Error(), "/sys/class/pwm/pwmchip0/pwm0/enable: no such file") } func TestI2cDefaultBus(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 0) + assert.Equal(t, 0, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -175,16 +174,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-2"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 2) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateI2cBusNumber(t *testing.T) { @@ -217,7 +216,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } diff --git a/platforms/jetson/jetson_adaptor_test.go b/platforms/jetson/jetson_adaptor_test.go index cc44db01a..a7529f16f 100644 --- a/platforms/jetson/jetson_adaptor_test.go +++ b/platforms/jetson/jetson_adaptor_test.go @@ -1,7 +1,6 @@ package jetson import ( - "errors" "fmt" "strings" "testing" @@ -10,11 +9,11 @@ import ( "strconv" "sync" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" "gobot.io/x/gobot/v2/drivers/spi" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -39,10 +38,10 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestNewAdaptor(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "JetsonNano"), true) + assert.True(t, strings.HasPrefix(a.Name(), "JetsonNano")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestFinalize(t *testing.T) { @@ -59,20 +58,20 @@ func TestFinalize(t *testing.T) { _ = a.DigitalWrite("3", 1) _, _ = a.GetI2cConnection(0xff, 0) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestPWMPinsConnect(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.pwmPins, (map[string]gobot.PWMPinner)(nil)) + assert.Equal(t, (map[string]gobot.PWMPinner)(nil), a.pwmPins) err := a.PwmWrite("33", 1) - gobottest.Assert(t, err.Error(), "not connected") + assert.Errorf(t, err, "not connected") err = a.Connect() - gobottest.Assert(t, err, nil) - gobottest.Refute(t, a.pwmPins, (map[string]gobot.PWMPinner)(nil)) - gobottest.Assert(t, len(a.pwmPins), 0) + assert.Nil(t, err) + assert.NotEqual(t, (map[string]gobot.PWMPinner)(nil), a.pwmPins) + assert.Equal(t, 0, len(a.pwmPins)) } func TestPWMPinsReConnect(t *testing.T) { @@ -85,15 +84,15 @@ func TestPWMPinsReConnect(t *testing.T) { "/sys/class/pwm/pwmchip0/pwm2/enable", } a, _ := initTestAdaptorWithMockedFilesystem(mockPaths) - gobottest.Assert(t, len(a.pwmPins), 0) - gobottest.Assert(t, a.PwmWrite("33", 1), nil) - gobottest.Assert(t, len(a.pwmPins), 1) - gobottest.Assert(t, a.Finalize(), nil) + assert.Equal(t, 0, len(a.pwmPins)) + assert.Nil(t, a.PwmWrite("33", 1)) + assert.Equal(t, 1, len(a.pwmPins)) + assert.Nil(t, a.Finalize()) // act err := a.Connect() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 0) + assert.Nil(t, err) + assert.Equal(t, 0, len(a.pwmPins)) } func TestDigitalIO(t *testing.T) { @@ -108,17 +107,17 @@ func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(mockPaths) err := a.DigitalWrite("7", 1) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio216/value"].Contents, "1") + assert.Nil(t, err) + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio216/value"].Contents) err = a.DigitalWrite("13", 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) i, err := a.DigitalRead("13") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, i, 1) + assert.Nil(t, err) + assert.Equal(t, 1, i) - gobottest.Assert(t, a.DigitalWrite("notexist", 1), errors.New("'notexist' is not a valid id for a digital pin")) - gobottest.Assert(t, a.Finalize(), nil) + assert.Errorf(t, a.DigitalWrite("notexist", 1), "'notexist' is not a valid id for a digital pin") + assert.Nil(t, a.Finalize()) } func TestDigitalPinConcurrency(t *testing.T) { @@ -147,15 +146,15 @@ func TestDigitalPinConcurrency(t *testing.T) { func TestSpiDefaultValues(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.SpiDefaultBusNumber(), 0) - gobottest.Assert(t, a.SpiDefaultChipNumber(), 0) - gobottest.Assert(t, a.SpiDefaultMode(), 0) - gobottest.Assert(t, a.SpiDefaultMaxSpeed(), int64(10000000)) + assert.Equal(t, 0, a.SpiDefaultBusNumber()) + assert.Equal(t, 0, a.SpiDefaultChipNumber()) + assert.Equal(t, 0, a.SpiDefaultMode()) + assert.Equal(t, int64(10000000), a.SpiDefaultMaxSpeed()) } func TestI2cDefaultBus(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 1) + assert.Equal(t, 1, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -163,16 +162,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-1"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateSpiBusNumber(t *testing.T) { @@ -202,7 +201,7 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -234,7 +233,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } diff --git a/platforms/jetson/pwm_pin_test.go b/platforms/jetson/pwm_pin_test.go index a67e58e5f..1c9cede1e 100644 --- a/platforms/jetson/pwm_pin_test.go +++ b/platforms/jetson/pwm_pin_test.go @@ -1,11 +1,10 @@ package jetson import ( - "errors" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -23,33 +22,33 @@ func TestPwmPin(t *testing.T) { a.UseMockFilesystem(mockPaths) pin := NewPWMPin(a, "/sys/class/pwm/pwmchip0", "0") - gobottest.Assert(t, pin.Export(), nil) - gobottest.Assert(t, pin.SetEnabled(true), nil) + assert.Nil(t, pin.Export()) + assert.Nil(t, pin.SetEnabled(true)) val, _ := pin.Polarity() - gobottest.Assert(t, val, true) - gobottest.Assert(t, pin.SetPolarity(false), nil) + assert.True(t, val) + assert.Nil(t, pin.SetPolarity(false)) val, _ = pin.Polarity() - gobottest.Assert(t, val, true) + assert.True(t, val) _, err := pin.Period() - gobottest.Assert(t, err, errors.New("Jetson PWM pin period not set")) - gobottest.Assert(t, pin.SetDutyCycle(10000), errors.New("Jetson PWM pin period not set")) + assert.Errorf(t, err, "Jetson PWM pin period not set") + assert.Errorf(t, pin.SetDutyCycle(10000), "Jetson PWM pin period not set") - gobottest.Assert(t, pin.SetPeriod(20000000), nil) + assert.Nil(t, pin.SetPeriod(20000000)) period, _ := pin.Period() - gobottest.Assert(t, period, uint32(20000000)) - gobottest.Assert(t, pin.SetPeriod(10000000), errors.New("Cannot set the period of individual PWM pins on Jetson")) + assert.Equal(t, uint32(20000000), period) + assert.Errorf(t, pin.SetPeriod(10000000), "Cannot set the period of individual PWM pins on Jetson") dc, _ := pin.DutyCycle() - gobottest.Assert(t, dc, uint32(0)) + assert.Equal(t, uint32(0), dc) - gobottest.Assert(t, pin.SetDutyCycle(10000), nil) + assert.Nil(t, pin.SetDutyCycle(10000)) dc, _ = pin.DutyCycle() - gobottest.Assert(t, dc, uint32(10000)) + assert.Equal(t, uint32(10000), dc) - gobottest.Assert(t, pin.SetDutyCycle(999999999), errors.New("Duty cycle exceeds period")) + assert.Errorf(t, pin.SetDutyCycle(999999999), "Duty cycle exceeds period") dc, _ = pin.DutyCycle() - gobottest.Assert(t, dc, uint32(10000)) + assert.Equal(t, uint32(10000), dc) - gobottest.Assert(t, pin.Unexport(), nil) + assert.Nil(t, pin.Unexport()) } diff --git a/platforms/joystick/joystick_driver_test.go b/platforms/joystick/joystick_driver_test.go index 334120584..0c581d4de 100644 --- a/platforms/joystick/joystick_driver_test.go +++ b/platforms/joystick/joystick_driver_test.go @@ -219,5 +219,5 @@ func TestDriverHandleEventDS4(t *testing.T) { func TestDriverInvalidConfig(t *testing.T) { d, _ := initTestDriver("./configs/doesnotexist") err := d.Start() - assert.True(t, strings.Contains(err.Error(), "loadfile error")) + assert.Contains(t, err.Error(), "loadfile error") } diff --git a/platforms/keyboard/keyboard_driver_test.go b/platforms/keyboard/keyboard_driver_test.go index 9ebb6147c..75327c42d 100644 --- a/platforms/keyboard/keyboard_driver_test.go +++ b/platforms/keyboard/keyboard_driver_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -23,22 +23,22 @@ func initTestKeyboardDriver() *Driver { func TestKeyboardDriver(t *testing.T) { d := initTestKeyboardDriver() - gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil)) + assert.Equal(t, (gobot.Connection)(nil), d.Connection()) } func TestKeyboardDriverName(t *testing.T) { d := initTestKeyboardDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Keyboard"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Keyboard")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestKeyboardDriverStart(t *testing.T) { d := initTestKeyboardDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestKeyboardDriverHalt(t *testing.T) { d := initTestKeyboardDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } diff --git a/platforms/keyboard/keyboard_test.go b/platforms/keyboard/keyboard_test.go index a8275895d..0ce7f0ed8 100644 --- a/platforms/keyboard/keyboard_test.go +++ b/platforms/keyboard/keyboard_test.go @@ -3,65 +3,65 @@ package keyboard import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestParseSpace(t *testing.T) { - gobottest.Assert(t, Parse(bytes{32, 0, 0}).Key, Spacebar) + assert.Equal(t, Spacebar, Parse(bytes{32, 0, 0}).Key) } func TestParseEscape(t *testing.T) { - gobottest.Assert(t, Parse(bytes{27, 0, 0}).Key, Escape) + assert.Equal(t, Escape, Parse(bytes{27, 0, 0}).Key) } func TestParseHyphen(t *testing.T) { - gobottest.Assert(t, Parse(bytes{45, 0, 0}).Key, Hyphen) + assert.Equal(t, Hyphen, Parse(bytes{45, 0, 0}).Key) } func TestParseAsterisk(t *testing.T) { - gobottest.Assert(t, Parse(bytes{42, 0, 0}).Key, Asterisk) + assert.Equal(t, Asterisk, Parse(bytes{42, 0, 0}).Key) } func TestParsePlus(t *testing.T) { - gobottest.Assert(t, Parse(bytes{43, 0, 0}).Key, Plus) + assert.Equal(t, Plus, Parse(bytes{43, 0, 0}).Key) } func TestParseSlash(t *testing.T) { - gobottest.Assert(t, Parse(bytes{47, 0, 0}).Key, Slash) + assert.Equal(t, Slash, Parse(bytes{47, 0, 0}).Key) } func TestParseDot(t *testing.T) { - gobottest.Assert(t, Parse(bytes{46, 0, 0}).Key, Dot) + assert.Equal(t, Dot, Parse(bytes{46, 0, 0}).Key) } func TestParseNotEscape(t *testing.T) { - gobottest.Refute(t, Parse(bytes{27, 91, 65}).Key, Escape) + assert.NotEqual(t, Escape, Parse(bytes{27, 91, 65}).Key) } func TestParseNumberKeys(t *testing.T) { - gobottest.Assert(t, Parse(bytes{48, 0, 0}).Key, 48) - gobottest.Assert(t, Parse(bytes{50, 0, 0}).Key, 50) - gobottest.Assert(t, Parse(bytes{57, 0, 0}).Key, 57) + assert.Equal(t, 48, Parse(bytes{48, 0, 0}).Key) + assert.Equal(t, 50, Parse(bytes{50, 0, 0}).Key) + assert.Equal(t, 57, Parse(bytes{57, 0, 0}).Key) } func TestParseAlphaKeys(t *testing.T) { - gobottest.Assert(t, Parse(bytes{97, 0, 0}).Key, 97) - gobottest.Assert(t, Parse(bytes{101, 0, 0}).Key, 101) - gobottest.Assert(t, Parse(bytes{122, 0, 0}).Key, 122) + assert.Equal(t, 97, Parse(bytes{97, 0, 0}).Key) + assert.Equal(t, 101, Parse(bytes{101, 0, 0}).Key) + assert.Equal(t, 122, Parse(bytes{122, 0, 0}).Key) } func TestParseNotAlphaKeys(t *testing.T) { - gobottest.Refute(t, Parse(bytes{132, 0, 0}).Key, 132) + assert.NotEqual(t, 132, Parse(bytes{132, 0, 0}).Key) } func TestParseArrowKeys(t *testing.T) { - gobottest.Assert(t, Parse(bytes{27, 91, 65}).Key, 65) - gobottest.Assert(t, Parse(bytes{27, 91, 66}).Key, 66) - gobottest.Assert(t, Parse(bytes{27, 91, 67}).Key, 67) - gobottest.Assert(t, Parse(bytes{27, 91, 68}).Key, 68) + assert.Equal(t, 65, Parse(bytes{27, 91, 65}).Key) + assert.Equal(t, 66, Parse(bytes{27, 91, 66}).Key) + assert.Equal(t, 67, Parse(bytes{27, 91, 67}).Key) + assert.Equal(t, 68, Parse(bytes{27, 91, 68}).Key) } func TestParseNotArrowKeys(t *testing.T) { - gobottest.Refute(t, Parse(bytes{27, 91, 65}).Key, Escape) - gobottest.Refute(t, Parse(bytes{27, 91, 70}).Key, 70) + assert.NotEqual(t, Escape, Parse(bytes{27, 91, 65}).Key) + assert.NotEqual(t, 70, Parse(bytes{27, 91, 70}).Key) } diff --git a/platforms/leap/leap_motion_adaptor_test.go b/platforms/leap/leap_motion_adaptor_test.go index bcc6449f4..0b4ef1c9e 100644 --- a/platforms/leap/leap_motion_adaptor_test.go +++ b/platforms/leap/leap_motion_adaptor_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -20,27 +20,27 @@ func initTestLeapMotionAdaptor() *Adaptor { func TestLeapMotionAdaptor(t *testing.T) { a := NewAdaptor("127.0.0.1") - gobottest.Assert(t, a.Port(), "127.0.0.1") + assert.Equal(t, "127.0.0.1", a.Port()) } func TestLeapMotionAdaptorName(t *testing.T) { a := NewAdaptor("127.0.0.1") - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Leap"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Leap")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestLeapMotionAdaptorConnect(t *testing.T) { a := initTestLeapMotionAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, errors.New("connection error") } - gobottest.Assert(t, a.Connect(), errors.New("connection error")) + assert.Errorf(t, a.Connect(), "connection error") } func TestLeapMotionAdaptorFinalize(t *testing.T) { a := initTestLeapMotionAdaptor() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } diff --git a/platforms/leap/leap_motion_driver_test.go b/platforms/leap/leap_motion_driver_test.go index 73dc0cd8c..735ad8e4a 100644 --- a/platforms/leap/leap_motion_driver_test.go +++ b/platforms/leap/leap_motion_driver_test.go @@ -8,8 +8,8 @@ import ( "sync" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -55,29 +55,29 @@ func initTestLeapMotionDriver() (*Driver, *NullReadWriteCloser) { func TestLeapMotionDriver(t *testing.T) { d, _ := initTestLeapMotionDriver() - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) } func TestLeapMotionDriverName(t *testing.T) { d, _ := initTestLeapMotionDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Leap"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Leap")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestLeapMotionDriverStart(t *testing.T) { d, _ := initTestLeapMotionDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) d2, rwc := initTestLeapMotionDriver() e := errors.New("write error") rwc.WriteError(e) - gobottest.Assert(t, d2.Start(), e) + assert.Equal(t, e, d2.Start()) } func TestLeapMotionDriverHalt(t *testing.T) { d, _ := initTestLeapMotionDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestLeapMotionDriverParser(t *testing.T) { @@ -89,18 +89,18 @@ func TestLeapMotionDriverParser(t *testing.T) { t.Errorf("ParseFrame incorrectly parsed frame") } - gobottest.Assert(t, parsedFrame.Timestamp, uint64(134211791358)) - gobottest.Assert(t, parsedFrame.Hands[0].X(), 247.410) - gobottest.Assert(t, parsedFrame.Hands[0].Y(), 275.868) - gobottest.Assert(t, parsedFrame.Hands[0].Z(), 132.843) + assert.Equal(t, uint64(134211791358), parsedFrame.Timestamp) + assert.Equal(t, 247.410, parsedFrame.Hands[0].X()) + assert.Equal(t, 275.868, parsedFrame.Hands[0].Y()) + assert.Equal(t, 132.843, parsedFrame.Hands[0].Z()) - gobottest.Assert(t, parsedFrame.Pointables[0].BTipPosition[0], 214.293) - gobottest.Assert(t, parsedFrame.Pointables[0].BTipPosition[1], 213.865) - gobottest.Assert(t, parsedFrame.Pointables[0].BTipPosition[2], 95.0224) + assert.Equal(t, 214.293, parsedFrame.Pointables[0].BTipPosition[0]) + assert.Equal(t, 213.865, parsedFrame.Pointables[0].BTipPosition[1]) + assert.Equal(t, 95.0224, parsedFrame.Pointables[0].BTipPosition[2]) - gobottest.Assert(t, parsedFrame.Pointables[0].Bases[0][0][0], -0.468069) - gobottest.Assert(t, parsedFrame.Pointables[0].Bases[0][0][1], 0.807844) - gobottest.Assert(t, parsedFrame.Pointables[0].Bases[0][0][2], -0.358190) + assert.Equal(t, -0.468069, parsedFrame.Pointables[0].Bases[0][0][0]) + assert.Equal(t, 0.807844, parsedFrame.Pointables[0].Bases[0][0][1]) + assert.Equal(t, -0.358190, parsedFrame.Pointables[0].Bases[0][0][2]) - gobottest.Assert(t, parsedFrame.Pointables[0].Width, 19.7871) + assert.Equal(t, 19.7871, parsedFrame.Pointables[0].Width) } diff --git a/platforms/mavlink/mavlink_adaptor_test.go b/platforms/mavlink/mavlink_adaptor_test.go index edc484a27..91408b295 100644 --- a/platforms/mavlink/mavlink_adaptor_test.go +++ b/platforms/mavlink/mavlink_adaptor_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -54,30 +54,30 @@ func initTestMavlinkAdaptor() *Adaptor { func TestMavlinkAdaptor(t *testing.T) { a := initTestMavlinkAdaptor() - gobottest.Assert(t, a.Port(), "/dev/null") + assert.Equal(t, "/dev/null", a.Port()) } func TestMavlinkAdaptorName(t *testing.T) { a := initTestMavlinkAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Mavlink"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Mavlink")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestMavlinkAdaptorConnect(t *testing.T) { a := initTestMavlinkAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, errors.New("connect error") } - gobottest.Assert(t, a.Connect(), errors.New("connect error")) + assert.Errorf(t, a.Connect(), "connect error") } func TestMavlinkAdaptorFinalize(t *testing.T) { a := initTestMavlinkAdaptor() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) testAdaptorClose = func() error { return errors.New("close error") } - gobottest.Assert(t, a.Finalize(), errors.New("close error")) + assert.Errorf(t, a.Finalize(), "close error") } diff --git a/platforms/mavlink/mavlink_driver_test.go b/platforms/mavlink/mavlink_driver_test.go index 4ac9c5cb4..fd7e628c3 100644 --- a/platforms/mavlink/mavlink_driver_test.go +++ b/platforms/mavlink/mavlink_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" common "gobot.io/x/gobot/v2/platforms/mavlink/common" ) @@ -26,18 +26,18 @@ func TestMavlinkDriver(t *testing.T) { m.connect = func(port string) (io.ReadWriteCloser, error) { return nil, nil } d := NewDriver(m) - gobottest.Refute(t, d.Connection(), nil) - gobottest.Assert(t, d.interval, 10*time.Millisecond) + assert.NotNil(t, d.Connection()) + assert.Equal(t, 10*time.Millisecond, d.interval) d = NewDriver(m, 100*time.Millisecond) - gobottest.Assert(t, d.interval, 100*time.Millisecond) + assert.Equal(t, 100*time.Millisecond, d.interval) } func TestMavlinkDriverName(t *testing.T) { d := initTestMavlinkDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Mavlink"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Mavlink")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestMavlinkDriverStart(t *testing.T) { @@ -59,11 +59,11 @@ func TestMavlinkDriverStart(t *testing.T) { err <- data.(error) }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) select { case p := <-packet: - gobottest.Assert(t, d.SendPacket(p), nil) + assert.Nil(t, d.SendPacket(p)) case <-time.After(100 * time.Millisecond): t.Errorf("packet was not emitted") @@ -82,5 +82,5 @@ func TestMavlinkDriverStart(t *testing.T) { func TestMavlinkDriverHalt(t *testing.T) { d := initTestMavlinkDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } diff --git a/platforms/mavlink/mavlink_udp_adaptor_test.go b/platforms/mavlink/mavlink_udp_adaptor_test.go index 5e9f1dd00..0bec533c8 100644 --- a/platforms/mavlink/mavlink_udp_adaptor_test.go +++ b/platforms/mavlink/mavlink_udp_adaptor_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" mavlink "gobot.io/x/gobot/v2/platforms/mavlink/common" ) @@ -53,20 +53,20 @@ func initTestMavlinkUDPAdaptor() *UDPAdaptor { func TestMavlinkUDPAdaptor(t *testing.T) { a := initTestMavlinkUDPAdaptor() - gobottest.Assert(t, a.Port(), ":14550") + assert.Equal(t, ":14550", a.Port()) } func TestMavlinkUDPAdaptorName(t *testing.T) { a := initTestMavlinkUDPAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Mavlink"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Mavlink")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestMavlinkUDPAdaptorConnectAndFinalize(t *testing.T) { a := initTestMavlinkUDPAdaptor() - gobottest.Assert(t, a.Connect(), nil) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Connect()) + assert.Nil(t, a.Finalize()) } func TestMavlinkUDPAdaptorWrite(t *testing.T) { @@ -81,8 +81,8 @@ func TestMavlinkUDPAdaptorWrite(t *testing.T) { a.sock = m i, err := a.Write([]byte{0x01, 0x02, 0x03}) - gobottest.Assert(t, i, 3) - gobottest.Assert(t, err, nil) + assert.Equal(t, 3, i) + assert.Nil(t, err) } func TestMavlinkReadMAVLinkReadDefaultPacket(t *testing.T) { @@ -101,7 +101,7 @@ func TestMavlinkReadMAVLinkReadDefaultPacket(t *testing.T) { a.sock = m p, _ := a.ReadMAVLinkPacket() - gobottest.Assert(t, p.Protocol, uint8(254)) + assert.Equal(t, uint8(254), p.Protocol) } func TestMavlinkReadMAVLinkPacketReadError(t *testing.T) { @@ -136,5 +136,5 @@ func TestMavlinkReadMAVLinkPacketReadError(t *testing.T) { a.sock = m _, err := a.ReadMAVLinkPacket() - gobottest.Assert(t, err, errors.New("read error")) + assert.Errorf(t, err, "read error") } diff --git a/platforms/microbit/accelerometer_driver_test.go b/platforms/microbit/accelerometer_driver_test.go index 7e1786c11..538cff44c 100644 --- a/platforms/microbit/accelerometer_driver_test.go +++ b/platforms/microbit/accelerometer_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*AccelerometerDriver)(nil) @@ -18,15 +18,15 @@ func initTestAccelerometerDriver() *AccelerometerDriver { func TestAccelerometerDriver(t *testing.T) { d := initTestAccelerometerDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit Accelerometer"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit Accelerometer")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestAccelerometerDriverStartAndHalt(t *testing.T) { d := initTestAccelerometerDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestAccelerometerDriverReadData(t *testing.T) { @@ -35,9 +35,9 @@ func TestAccelerometerDriverReadData(t *testing.T) { d := NewAccelerometerDriver(a) _ = d.Start() _ = d.On(Accelerometer, func(data interface{}) { - gobottest.Assert(t, data.(*AccelerometerData).X, float32(8.738)) - gobottest.Assert(t, data.(*AccelerometerData).Y, float32(8.995)) - gobottest.Assert(t, data.(*AccelerometerData).Z, float32(9.252)) + assert.Equal(t, float32(8.738), data.(*AccelerometerData).X) + assert.Equal(t, float32(8.995), data.(*AccelerometerData).Y) + assert.Equal(t, float32(9.252), data.(*AccelerometerData).Z) sem <- true }) diff --git a/platforms/microbit/button_driver_test.go b/platforms/microbit/button_driver_test.go index 007f3881c..adde9c703 100644 --- a/platforms/microbit/button_driver_test.go +++ b/platforms/microbit/button_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*ButtonDriver)(nil) @@ -18,15 +18,15 @@ func initTestButtonDriver() *ButtonDriver { func TestButtonDriver(t *testing.T) { d := initTestButtonDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit Button"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit Button")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestButtonDriverStartAndHalt(t *testing.T) { d := initTestButtonDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestButtonDriverReadData(t *testing.T) { diff --git a/platforms/microbit/io_pin_driver_test.go b/platforms/microbit/io_pin_driver_test.go index ceda71d95..ace606c7d 100644 --- a/platforms/microbit/io_pin_driver_test.go +++ b/platforms/microbit/io_pin_driver_test.go @@ -5,10 +5,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/aio" "gobot.io/x/gobot/v2/drivers/gpio" - "gobot.io/x/gobot/v2/gobottest" ) // the IOPinDriver is a Driver @@ -26,9 +26,9 @@ func initTestIOPinDriver() *IOPinDriver { func TestIOPinDriver(t *testing.T) { d := initTestIOPinDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit IO Pin"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit IO Pin")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestIOPinDriverStartAndHalt(t *testing.T) { @@ -37,8 +37,8 @@ func TestIOPinDriverStartAndHalt(t *testing.T) { a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { return []byte{0, 1, 1, 0}, nil }) - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestIOPinDriverStartError(t *testing.T) { @@ -47,7 +47,7 @@ func TestIOPinDriverStartError(t *testing.T) { a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { return nil, errors.New("read error") }) - gobottest.Assert(t, d.Start(), errors.New("read error")) + assert.Errorf(t, d.Start(), "read error") } func TestIOPinDriverDigitalRead(t *testing.T) { @@ -58,10 +58,10 @@ func TestIOPinDriverDigitalRead(t *testing.T) { }) val, _ := d.DigitalRead("0") - gobottest.Assert(t, val, 1) + assert.Equal(t, 1, val) val, _ = d.DigitalRead("1") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) } func TestIOPinDriverDigitalReadInvalidPin(t *testing.T) { @@ -69,10 +69,10 @@ func TestIOPinDriverDigitalReadInvalidPin(t *testing.T) { d := NewIOPinDriver(a) _, err := d.DigitalRead("A3") - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) _, err = d.DigitalRead("6") - gobottest.Assert(t, err, errors.New("Invalid pin.")) + assert.Errorf(t, err, "Invalid pin.") } func TestIOPinDriverDigitalWrite(t *testing.T) { @@ -80,15 +80,15 @@ func TestIOPinDriverDigitalWrite(t *testing.T) { d := NewIOPinDriver(a) // TODO: a better test - gobottest.Assert(t, d.DigitalWrite("0", 1), nil) + assert.Nil(t, d.DigitalWrite("0", 1)) } func TestIOPinDriverDigitalWriteInvalidPin(t *testing.T) { a := NewBleTestAdaptor() d := NewIOPinDriver(a) - gobottest.Refute(t, d.DigitalWrite("A3", 1), nil) - gobottest.Assert(t, d.DigitalWrite("6", 1), errors.New("Invalid pin.")) + assert.NotNil(t, d.DigitalWrite("A3", 1)) + assert.Errorf(t, d.DigitalWrite("6", 1), "Invalid pin.") } func TestIOPinDriverAnalogRead(t *testing.T) { @@ -99,10 +99,10 @@ func TestIOPinDriverAnalogRead(t *testing.T) { }) val, _ := d.AnalogRead("0") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) val, _ = d.AnalogRead("1") - gobottest.Assert(t, val, 128) + assert.Equal(t, 128, val) } func TestIOPinDriverAnalogReadInvalidPin(t *testing.T) { @@ -110,10 +110,10 @@ func TestIOPinDriverAnalogReadInvalidPin(t *testing.T) { d := NewIOPinDriver(a) _, err := d.AnalogRead("A3") - gobottest.Refute(t, err, nil) + assert.NotNil(t, err) _, err = d.AnalogRead("6") - gobottest.Assert(t, err, errors.New("Invalid pin.")) + assert.Errorf(t, err, "Invalid pin.") } func TestIOPinDriverDigitalAnalogRead(t *testing.T) { @@ -124,10 +124,10 @@ func TestIOPinDriverDigitalAnalogRead(t *testing.T) { }) val, _ := d.DigitalRead("0") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) val, _ = d.AnalogRead("0") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) } func TestIOPinDriverDigitalWriteAnalogRead(t *testing.T) { @@ -137,10 +137,10 @@ func TestIOPinDriverDigitalWriteAnalogRead(t *testing.T) { return []byte{0, 0, 1, 128, 2, 1}, nil }) - gobottest.Assert(t, d.DigitalWrite("1", 0), nil) + assert.Nil(t, d.DigitalWrite("1", 0)) val, _ := d.AnalogRead("1") - gobottest.Assert(t, val, 128) + assert.Equal(t, 128, val) } func TestIOPinDriverAnalogReadDigitalWrite(t *testing.T) { @@ -151,7 +151,7 @@ func TestIOPinDriverAnalogReadDigitalWrite(t *testing.T) { }) val, _ := d.AnalogRead("1") - gobottest.Assert(t, val, 128) + assert.Equal(t, 128, val) - gobottest.Assert(t, d.DigitalWrite("1", 0), nil) + assert.Nil(t, d.DigitalWrite("1", 0)) } diff --git a/platforms/microbit/led_driver_test.go b/platforms/microbit/led_driver_test.go index 9d4003c20..fb24f147b 100644 --- a/platforms/microbit/led_driver_test.go +++ b/platforms/microbit/led_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*LEDDriver)(nil) @@ -17,39 +17,39 @@ func initTestLEDDriver() *LEDDriver { func TestLEDDriver(t *testing.T) { d := initTestLEDDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit LED"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit LED")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestLEDDriverStartAndHalt(t *testing.T) { d := initTestLEDDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestLEDDriverWriteMatrix(t *testing.T) { d := initTestLEDDriver() _ = d.Start() - gobottest.Assert(t, d.WriteMatrix([]byte{0x01, 0x02}), nil) + assert.Nil(t, d.WriteMatrix([]byte{0x01, 0x02})) } func TestLEDDriverWriteText(t *testing.T) { d := initTestLEDDriver() _ = d.Start() - gobottest.Assert(t, d.WriteText("Hello"), nil) + assert.Nil(t, d.WriteText("Hello")) } func TestLEDDriverCommands(t *testing.T) { d := initTestLEDDriver() _ = d.Start() - gobottest.Assert(t, d.Blank(), nil) - gobottest.Assert(t, d.Solid(), nil) - gobottest.Assert(t, d.UpRightArrow(), nil) - gobottest.Assert(t, d.UpLeftArrow(), nil) - gobottest.Assert(t, d.DownRightArrow(), nil) - gobottest.Assert(t, d.DownLeftArrow(), nil) - gobottest.Assert(t, d.Dimond(), nil) - gobottest.Assert(t, d.Smile(), nil) - gobottest.Assert(t, d.Wink(), nil) + assert.Nil(t, d.Blank()) + assert.Nil(t, d.Solid()) + assert.Nil(t, d.UpRightArrow()) + assert.Nil(t, d.UpLeftArrow()) + assert.Nil(t, d.DownRightArrow()) + assert.Nil(t, d.DownLeftArrow()) + assert.Nil(t, d.Dimond()) + assert.Nil(t, d.Smile()) + assert.Nil(t, d.Wink()) } diff --git a/platforms/microbit/magnetometer_driver_test.go b/platforms/microbit/magnetometer_driver_test.go index 03ef4145f..7a9e0bde9 100644 --- a/platforms/microbit/magnetometer_driver_test.go +++ b/platforms/microbit/magnetometer_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*MagnetometerDriver)(nil) @@ -18,15 +18,15 @@ func initTestMagnetometerDriver() *MagnetometerDriver { func TestMagnetometerDriver(t *testing.T) { d := initTestMagnetometerDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit Magnetometer"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit Magnetometer")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestMagnetometerDriverStartAndHalt(t *testing.T) { d := initTestMagnetometerDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestMagnetometerDriverReadData(t *testing.T) { @@ -35,9 +35,9 @@ func TestMagnetometerDriverReadData(t *testing.T) { d := NewMagnetometerDriver(a) _ = d.Start() _ = d.On(Magnetometer, func(data interface{}) { - gobottest.Assert(t, data.(*MagnetometerData).X, float32(8.738)) - gobottest.Assert(t, data.(*MagnetometerData).Y, float32(8.995)) - gobottest.Assert(t, data.(*MagnetometerData).Z, float32(9.252)) + assert.Equal(t, float32(8.738), data.(*MagnetometerData).X) + assert.Equal(t, float32(8.995), data.(*MagnetometerData).Y) + assert.Equal(t, float32(9.252), data.(*MagnetometerData).Z) sem <- true }) diff --git a/platforms/microbit/temperature_driver_test.go b/platforms/microbit/temperature_driver_test.go index 8abeef661..4ab2bb4a1 100644 --- a/platforms/microbit/temperature_driver_test.go +++ b/platforms/microbit/temperature_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*TemperatureDriver)(nil) @@ -18,15 +18,15 @@ func initTestTemperatureDriver() *TemperatureDriver { func TestTemperatureDriver(t *testing.T) { d := initTestTemperatureDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit Temperature"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Microbit Temperature")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestTemperatureDriverStartAndHalt(t *testing.T) { d := initTestTemperatureDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestTemperatureDriverReadData(t *testing.T) { @@ -35,7 +35,7 @@ func TestTemperatureDriverReadData(t *testing.T) { d := NewTemperatureDriver(a) _ = d.Start() _ = d.On(Temperature, func(data interface{}) { - gobottest.Assert(t, data, int8(0x22)) + assert.Equal(t, int8(0x22), data) sem <- true }) diff --git a/platforms/mqtt/mqtt_adaptor_test.go b/platforms/mqtt/mqtt_adaptor_test.go index db27ec67e..b36a4e4eb 100644 --- a/platforms/mqtt/mqtt_adaptor_test.go +++ b/platforms/mqtt/mqtt_adaptor_test.go @@ -1,13 +1,12 @@ package mqtt import ( - "errors" "fmt" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -18,112 +17,112 @@ func initTestMqttAdaptor() *Adaptor { func TestMqttAdaptorName(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "MQTT"), true) + assert.True(t, strings.HasPrefix(a.Name(), "MQTT")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestMqttAdaptorPort(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.Port(), "tcp://localhost:1883") + assert.Equal(t, "tcp://localhost:1883", a.Port()) } func TestMqttAdaptorAutoReconnect(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.AutoReconnect(), false) + assert.False(t, a.AutoReconnect()) a.SetAutoReconnect(true) - gobottest.Assert(t, a.AutoReconnect(), true) + assert.True(t, a.AutoReconnect()) } func TestMqttAdaptorCleanSession(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.CleanSession(), true) + assert.True(t, a.CleanSession()) a.SetCleanSession(false) - gobottest.Assert(t, a.CleanSession(), false) + assert.False(t, a.CleanSession()) } func TestMqttAdaptorUseSSL(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.UseSSL(), false) + assert.False(t, a.UseSSL()) a.SetUseSSL(true) - gobottest.Assert(t, a.UseSSL(), true) + assert.True(t, a.UseSSL()) } func TestMqttAdaptorUseServerCert(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.ServerCert(), "") + assert.Equal(t, "", a.ServerCert()) a.SetServerCert("/path/to/server.cert") - gobottest.Assert(t, a.ServerCert(), "/path/to/server.cert") + assert.Equal(t, "/path/to/server.cert", a.ServerCert()) } func TestMqttAdaptorUseClientCert(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.ClientCert(), "") + assert.Equal(t, "", a.ClientCert()) a.SetClientCert("/path/to/client.cert") - gobottest.Assert(t, a.ClientCert(), "/path/to/client.cert") + assert.Equal(t, "/path/to/client.cert", a.ClientCert()) } func TestMqttAdaptorUseClientKey(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.ClientKey(), "") + assert.Equal(t, "", a.ClientKey()) a.SetClientKey("/path/to/client.key") - gobottest.Assert(t, a.ClientKey(), "/path/to/client.key") + assert.Equal(t, "/path/to/client.key", a.ClientKey()) } func TestMqttAdaptorConnectError(t *testing.T) { a := NewAdaptor("tcp://localhost:1884", "client") err := a.Connect() - gobottest.Assert(t, strings.Contains(err.Error(), "connection refused"), true) + assert.Contains(t, err.Error(), "connection refused") } func TestMqttAdaptorConnectSSLError(t *testing.T) { a := NewAdaptor("tcp://localhost:1884", "client") a.SetUseSSL(true) err := a.Connect() - gobottest.Assert(t, strings.Contains(err.Error(), "connection refused"), true) + assert.Contains(t, err.Error(), "connection refused") } func TestMqttAdaptorConnectWithAuthError(t *testing.T) { a := NewAdaptorWithAuth("xyz://localhost:1883", "client", "user", "pass") - gobottest.Assert(t, a.Connect(), errors.New("network Error : unknown protocol")) + assert.Errorf(t, a.Connect(), "network Error : unknown protocol") } func TestMqttAdaptorFinalize(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestMqttAdaptorCannotPublishUnlessConnected(t *testing.T) { a := initTestMqttAdaptor() data := []byte("o") - gobottest.Assert(t, a.Publish("test", data), false) + assert.False(t, a.Publish("test", data)) } func TestMqttAdaptorPublishWhenConnected(t *testing.T) { a := initTestMqttAdaptor() _ = a.Connect() data := []byte("o") - gobottest.Assert(t, a.Publish("test", data), true) + assert.True(t, a.Publish("test", data)) } func TestMqttAdaptorCannotOnUnlessConnected(t *testing.T) { a := initTestMqttAdaptor() - gobottest.Assert(t, a.On("hola", func(msg Message) { + assert.False(t, a.On("hola", func(msg Message) { fmt.Println("hola") - }), false) + })) } func TestMqttAdaptorOnWhenConnected(t *testing.T) { a := initTestMqttAdaptor() _ = a.Connect() - gobottest.Assert(t, a.On("hola", func(msg Message) { + assert.True(t, a.On("hola", func(msg Message) { fmt.Println("hola") - }), true) + })) } func TestMqttAdaptorQoS(t *testing.T) { a := initTestMqttAdaptor() a.SetQoS(1) - gobottest.Assert(t, 1, a.qos) + assert.Equal(t, a.qos, 1) } diff --git a/platforms/mqtt/mqtt_driver_test.go b/platforms/mqtt/mqtt_driver_test.go index 028838db7..1cbfe29db 100644 --- a/platforms/mqtt/mqtt_driver_test.go +++ b/platforms/mqtt/mqtt_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -13,25 +13,25 @@ var _ gobot.Driver = (*Driver)(nil) func TestMqttDriver(t *testing.T) { d := NewDriver(initTestMqttAdaptor(), "/test/topic") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MQTT"), true) - gobottest.Assert(t, strings.HasPrefix(d.Connection().Name(), "MQTT"), true) + assert.True(t, strings.HasPrefix(d.Name(), "MQTT")) + assert.True(t, strings.HasPrefix(d.Connection().Name(), "MQTT")) - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestMqttDriverName(t *testing.T) { d := NewDriver(initTestMqttAdaptor(), "/test/topic") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "MQTT"), true) + assert.True(t, strings.HasPrefix(d.Name(), "MQTT")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestMqttDriverTopic(t *testing.T) { d := NewDriver(initTestMqttAdaptor(), "/test/topic") - gobottest.Assert(t, d.Topic(), "/test/topic") + assert.Equal(t, "/test/topic", d.Topic()) d.SetTopic("/test/newtopic") - gobottest.Assert(t, d.Topic(), "/test/newtopic") + assert.Equal(t, "/test/newtopic", d.Topic()) } func TestMqttDriverPublish(t *testing.T) { @@ -40,7 +40,7 @@ func TestMqttDriverPublish(t *testing.T) { _ = a.Connect() _ = d.Start() defer func() { _ = d.Halt() }() - gobottest.Assert(t, d.Publish([]byte{0x01, 0x02, 0x03}), true) + assert.True(t, d.Publish([]byte{0x01, 0x02, 0x03})) } func TestMqttDriverPublishError(t *testing.T) { @@ -48,5 +48,5 @@ func TestMqttDriverPublishError(t *testing.T) { d := NewDriver(a, "/test/topic") _ = d.Start() defer func() { _ = d.Halt() }() - gobottest.Assert(t, d.Publish([]byte{0x01, 0x02, 0x03}), false) + assert.False(t, d.Publish([]byte{0x01, 0x02, 0x03})) } diff --git a/platforms/nanopi/nanopi_adaptor_test.go b/platforms/nanopi/nanopi_adaptor_test.go index e6681c047..e75bc6397 100644 --- a/platforms/nanopi/nanopi_adaptor_test.go +++ b/platforms/nanopi/nanopi_adaptor_test.go @@ -5,10 +5,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -74,9 +74,9 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestName(t *testing.T) { a := NewNeoAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "NanoPi NEO Board"), true) + assert.True(t, strings.HasPrefix(a.Name(), "NanoPi NEO Board")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestDigitalIO(t *testing.T) { @@ -84,14 +84,14 @@ func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) _ = a.DigitalWrite("7", 1) - gobottest.Assert(t, fs.Files[gpio203Path+"value"].Contents, "1") + assert.Equal(t, "1", fs.Files[gpio203Path+"value"].Contents) fs.Files[gpio199Path+"value"].Contents = "1" i, _ := a.DigitalRead("10") - gobottest.Assert(t, i, 1) + assert.Equal(t, 1, i) - gobottest.Assert(t, a.DigitalWrite("99", 1), fmt.Errorf("'99' is not a valid id for a digital pin")) - gobottest.Assert(t, a.Finalize(), nil) + assert.Errorf(t, a.DigitalWrite("99", 1), "'99' is not a valid id for a digital pin") + assert.Nil(t, a.Finalize()) } func TestInvalidPWMPin(t *testing.T) { @@ -99,16 +99,16 @@ func TestInvalidPWMPin(t *testing.T) { preparePwmFs(fs) err := a.PwmWrite("666", 42) - gobottest.Assert(t, err.Error(), "'666' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'666' is not a valid id for a PWM pin") err = a.ServoWrite("666", 120) - gobottest.Assert(t, err.Error(), "'666' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'666' is not a valid id for a PWM pin") err = a.PwmWrite("3", 42) - gobottest.Assert(t, err.Error(), "'3' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'3' is not a valid id for a PWM pin") err = a.ServoWrite("3", 120) - gobottest.Assert(t, err.Error(), "'3' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'3' is not a valid id for a PWM pin") } func TestPwmWrite(t *testing.T) { @@ -116,24 +116,24 @@ func TestPwmWrite(t *testing.T) { preparePwmFs(fs) err := a.PwmWrite("PWM", 100) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmExportPath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmEnablePath].Contents, "1") - gobottest.Assert(t, fs.Files[pwmPeriodPath].Contents, fmt.Sprintf("%d", 10000000)) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "3921568") - gobottest.Assert(t, fs.Files[pwmPolarityPath].Contents, "normal") + assert.Equal(t, "0", fs.Files[pwmExportPath].Contents) + assert.Equal(t, "1", fs.Files[pwmEnablePath].Contents) + assert.Equal(t, fmt.Sprintf("%d", 10000000), fs.Files[pwmPeriodPath].Contents) + assert.Equal(t, "3921568", fs.Files[pwmDutyCyclePath].Contents) + assert.Equal(t, "normal", fs.Files[pwmPolarityPath].Contents) err = a.ServoWrite("PWM", 0) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "500000") + assert.Equal(t, "500000", fs.Files[pwmDutyCyclePath].Contents) err = a.ServoWrite("PWM", 180) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "2000000") - gobottest.Assert(t, a.Finalize(), nil) + assert.Equal(t, "2000000", fs.Files[pwmDutyCyclePath].Contents) + assert.Nil(t, a.Finalize()) } func TestSetPeriod(t *testing.T) { @@ -145,25 +145,25 @@ func TestSetPeriod(t *testing.T) { // act err := a.SetPeriod("PWM", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmExportPath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmEnablePath].Contents, "1") - gobottest.Assert(t, fs.Files[pwmPeriodPath].Contents, fmt.Sprintf("%d", newPeriod)) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmPolarityPath].Contents, "normal") + assert.Nil(t, err) + assert.Equal(t, "0", fs.Files[pwmExportPath].Contents) + assert.Equal(t, "1", fs.Files[pwmEnablePath].Contents) + assert.Equal(t, fmt.Sprintf("%d", newPeriod), fs.Files[pwmPeriodPath].Contents) + assert.Equal(t, "0", fs.Files[pwmDutyCyclePath].Contents) + assert.Equal(t, "normal", fs.Files[pwmPolarityPath].Contents) // arrange test for automatic adjustment of duty cycle to lower value err = a.PwmWrite("PWM", 127) // 127 is a little bit smaller than 50% of period - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 1270000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 1270000), fs.Files[pwmDutyCyclePath].Contents) newPeriod = newPeriod / 10 // act err = a.SetPeriod("PWM", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 127000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 127000), fs.Files[pwmDutyCyclePath].Contents) // arrange test for automatic adjustment of duty cycle to higher value newPeriod = newPeriod * 20 @@ -172,46 +172,46 @@ func TestSetPeriod(t *testing.T) { err = a.SetPeriod("PWM", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 2540000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 2540000), fs.Files[pwmDutyCyclePath].Contents) } func TestFinalizeErrorAfterGPIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) - gobottest.Assert(t, a.DigitalWrite("7", 1), nil) + assert.Nil(t, a.DigitalWrite("7", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestFinalizeErrorAfterPWM(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(pwmMockPaths) preparePwmFs(fs) - gobottest.Assert(t, a.PwmWrite("PWM", 1), nil) + assert.Nil(t, a.PwmWrite("PWM", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestSpiDefaultValues(t *testing.T) { a := NewNeoAdaptor() - gobottest.Assert(t, a.SpiDefaultBusNumber(), 0) - gobottest.Assert(t, a.SpiDefaultChipNumber(), 0) - gobottest.Assert(t, a.SpiDefaultMode(), 0) - gobottest.Assert(t, a.SpiDefaultBitCount(), 8) - gobottest.Assert(t, a.SpiDefaultMaxSpeed(), int64(500000)) + assert.Equal(t, 0, a.SpiDefaultBusNumber()) + assert.Equal(t, 0, a.SpiDefaultChipNumber()) + assert.Equal(t, 0, a.SpiDefaultMode()) + assert.Equal(t, 8, a.SpiDefaultBitCount()) + assert.Equal(t, int64(500000), a.SpiDefaultMaxSpeed()) } func TestI2cDefaultBus(t *testing.T) { a := NewNeoAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 0) + assert.Equal(t, 0, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -219,16 +219,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewNeoAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-1"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateSpiBusNumber(t *testing.T) { @@ -255,7 +255,7 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -290,7 +290,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -330,9 +330,9 @@ func Test_translateDigitalPin(t *testing.T) { // act chip, line, err := a.translateDigitalPin(tc.pin) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, chip, tc.wantChip) - gobottest.Assert(t, line, tc.wantLine) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantChip, chip) + assert.Equal(t, tc.wantLine, line) }) } } @@ -370,9 +370,9 @@ func Test_translatePWMPin(t *testing.T) { // act dir, channel, err := a.translatePWMPin(tc.pin) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, dir, tc.wantDir) - gobottest.Assert(t, channel, tc.wantChannel) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantDir, dir) + assert.Equal(t, tc.wantChannel, channel) }) } } diff --git a/platforms/nats/nats_adaptor_test.go b/platforms/nats/nats_adaptor_test.go index 469ec6f2b..9ab2dcbde 100644 --- a/platforms/nats/nats_adaptor_test.go +++ b/platforms/nats/nats_adaptor_test.go @@ -1,15 +1,14 @@ package nats import ( - "errors" "fmt" "log" "strings" "testing" "github.com/nats-io/nats.go" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -53,55 +52,55 @@ func initTestNatsAdaptorTLS(options ...nats.Option) *Adaptor { func TestNatsAdaptorName(t *testing.T) { a := initTestNatsAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "NATS"), true) + assert.True(t, strings.HasPrefix(a.Name(), "NATS")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestNatsAdaptorReturnsHost(t *testing.T) { a := initTestNatsAdaptor() - gobottest.Assert(t, a.Host, "nats://localhost:4222") + assert.Equal(t, "nats://localhost:4222", a.Host) } func TestNatsAdaptorWithAuth(t *testing.T) { a := initTestNatsAdaptorWithAuth() - gobottest.Assert(t, a.username, "user") - gobottest.Assert(t, a.password, "pass") + assert.Equal(t, "user", a.username) + assert.Equal(t, "pass", a.password) } func TestNatsAdapterSetsRootCAs(t *testing.T) { a := initTestNatsAdaptorTLS(nats.RootCAs("test_certs/catest.pem")) - gobottest.Assert(t, a.Host, "tls://localhost:4242") + assert.Equal(t, "tls://localhost:4242", a.Host) _ = a.Connect() o := a.client.Opts casPool, err := o.RootCAsCB() - gobottest.Assert(t, err, nil) - gobottest.Refute(t, casPool, nil) - gobottest.Assert(t, o.Secure, true) + assert.Nil(t, err) + assert.NotNil(t, casPool) + assert.True(t, o.Secure) } func TestNatsAdapterSetsClientCerts(t *testing.T) { a := initTestNatsAdaptorTLS(nats.ClientCert("test_certs/client-cert.pem", "test_certs/client-key.pem")) - gobottest.Assert(t, a.Host, "tls://localhost:4242") + assert.Equal(t, "tls://localhost:4242", a.Host) _ = a.Connect() cert, err := a.client.Opts.TLSCertCB() - gobottest.Assert(t, err, nil) - gobottest.Refute(t, cert, nil) - gobottest.Refute(t, cert.Leaf, nil) - gobottest.Assert(t, a.client.Opts.Secure, true) + assert.Nil(t, err) + assert.NotNil(t, cert) + assert.NotNil(t, cert.Leaf) + assert.True(t, a.client.Opts.Secure) } func TestNatsAdapterSetsClientCertsWithUserInfo(t *testing.T) { a := initTestNatsAdaptorTLS(nats.ClientCert("test_certs/client-cert.pem", "test_certs/client-key.pem"), nats.UserInfo("test", "testwd")) - gobottest.Assert(t, a.Host, "tls://localhost:4242") + assert.Equal(t, "tls://localhost:4242", a.Host) _ = a.Connect() cert, err := a.client.Opts.TLSCertCB() - gobottest.Assert(t, err, nil) - gobottest.Refute(t, cert, nil) - gobottest.Refute(t, cert.Leaf, nil) - gobottest.Assert(t, a.client.Opts.Secure, true) - gobottest.Assert(t, a.client.Opts.User, "test") - gobottest.Assert(t, a.client.Opts.Password, "testwd") + assert.Nil(t, err) + assert.NotNil(t, cert) + assert.NotNil(t, cert.Leaf) + assert.True(t, a.client.Opts.Secure) + assert.Equal(t, "test", a.client.Opts.User) + assert.Equal(t, "testwd", a.client.Opts.Password) } // TODO: implement this test without requiring actual server connection @@ -110,7 +109,7 @@ func TestNatsAdaptorPublishWhenConnected(t *testing.T) { a := initTestNatsAdaptor() _ = a.Connect() data := []byte("o") - gobottest.Assert(t, a.Publish("test", data), true) + assert.True(t, a.Publish("test", data)) } // TODO: implement this test without requiring actual server connection @@ -118,9 +117,9 @@ func TestNatsAdaptorOnWhenConnected(t *testing.T) { t.Skip("TODO: implement this test without requiring actual server connection") a := initTestNatsAdaptor() _ = a.Connect() - gobottest.Assert(t, a.On("hola", func(msg Message) { + assert.True(t, a.On("hola", func(msg Message) { fmt.Println("hola") - }), true) + })) } // TODO: implement this test without requiring actual server connection @@ -129,7 +128,7 @@ func TestNatsAdaptorPublishWhenConnectedWithAuth(t *testing.T) { a := NewAdaptorWithAuth("localhost:4222", 49999, "test", "testwd") _ = a.Connect() data := []byte("o") - gobottest.Assert(t, a.Publish("test", data), true) + assert.True(t, a.Publish("test", data)) } // TODO: implement this test without requiring actual server connection @@ -138,9 +137,9 @@ func TestNatsAdaptorOnWhenConnectedWithAuth(t *testing.T) { log.Println("###not skipped###") a := NewAdaptorWithAuth("localhost:4222", 59999, "test", "testwd") _ = a.Connect() - gobottest.Assert(t, a.On("hola", func(msg Message) { + assert.True(t, a.On("hola", func(msg Message) { fmt.Println("hola") - }), true) + })) } func TestNatsAdaptorFailedConnect(t *testing.T) { @@ -149,23 +148,23 @@ func TestNatsAdaptorFailedConnect(t *testing.T) { if err != nil && strings.Contains(err.Error(), "cannot assign requested address") { t.Skip("FLAKY: Can not test, because IP or port is in use.") } - gobottest.Assert(t, err, errors.New("nats: no servers available for connection")) + assert.Errorf(t, err, "nats: no servers available for connection") } func TestNatsAdaptorFinalize(t *testing.T) { a := NewAdaptor("localhost:9999", 79999) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestNatsAdaptorCannotPublishUnlessConnected(t *testing.T) { a := NewAdaptor("localhost:9999", 89999) data := []byte("o") - gobottest.Assert(t, a.Publish("test", data), false) + assert.False(t, a.Publish("test", data)) } func TestNatsAdaptorCannotOnUnlessConnected(t *testing.T) { a := NewAdaptor("localhost:9999", 99999) - gobottest.Assert(t, a.On("hola", func(msg Message) { + assert.False(t, a.On("hola", func(msg Message) { fmt.Println("hola") - }), false) + })) } diff --git a/platforms/nats/nats_driver_test.go b/platforms/nats/nats_driver_test.go index 2725df02f..7c8a14c61 100644 --- a/platforms/nats/nats_driver_test.go +++ b/platforms/nats/nats_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -13,23 +13,23 @@ var _ gobot.Driver = (*Driver)(nil) func TestNatsDriver(t *testing.T) { d := NewDriver(initTestNatsAdaptor(), "/test/topic") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "NATS"), true) - gobottest.Assert(t, strings.HasPrefix(d.Connection().Name(), "NATS"), true) - gobottest.Refute(t, d.adaptor(), nil) + assert.True(t, strings.HasPrefix(d.Name(), "NATS")) + assert.True(t, strings.HasPrefix(d.Connection().Name(), "NATS")) + assert.NotNil(t, d.adaptor()) - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestNatsDriverName(t *testing.T) { d := NewDriver(initTestNatsAdaptor(), "/test/topic") - gobottest.Assert(t, strings.HasPrefix(d.Name(), "NATS"), true) + assert.True(t, strings.HasPrefix(d.Name(), "NATS")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestNatsDriverTopic(t *testing.T) { d := NewDriver(initTestNatsAdaptor(), "/test/topic") d.SetTopic("interestingtopic") - gobottest.Assert(t, d.Topic(), "interestingtopic") + assert.Equal(t, "interestingtopic", d.Topic()) } diff --git a/platforms/neurosky/neurosky_adaptor_test.go b/platforms/neurosky/neurosky_adaptor_test.go index 74237ec7a..2089d16d4 100644 --- a/platforms/neurosky/neurosky_adaptor_test.go +++ b/platforms/neurosky/neurosky_adaptor_test.go @@ -7,8 +7,8 @@ import ( "sync" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -57,24 +57,24 @@ func initTestNeuroskyAdaptor() *Adaptor { func TestNeuroskyAdaptor(t *testing.T) { a := NewAdaptor("/dev/null") - gobottest.Assert(t, a.Port(), "/dev/null") + assert.Equal(t, "/dev/null", a.Port()) } func TestNeuroskyAdaptorName(t *testing.T) { a := NewAdaptor("/dev/null") - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Neurosky"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Neurosky")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestNeuroskyAdaptorConnect(t *testing.T) { a := initTestNeuroskyAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(n *Adaptor) (io.ReadWriteCloser, error) { return nil, errors.New("connection error") } - gobottest.Assert(t, a.Connect(), errors.New("connection error")) + assert.Errorf(t, a.Connect(), "connection error") } func TestNeuroskyAdaptorFinalize(t *testing.T) { @@ -84,9 +84,9 @@ func TestNeuroskyAdaptorFinalize(t *testing.T) { return rwc, nil } _ = a.Connect() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) rwc.CloseError(errors.New("close error")) _ = a.Connect() - gobottest.Assert(t, a.Finalize(), errors.New("close error")) + assert.Errorf(t, a.Finalize(), "close error") } diff --git a/platforms/neurosky/neurosky_driver_test.go b/platforms/neurosky/neurosky_driver_test.go index 9f83f5387..6a85a44a4 100644 --- a/platforms/neurosky/neurosky_driver_test.go +++ b/platforms/neurosky/neurosky_driver_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -25,14 +25,14 @@ func initTestNeuroskyDriver() *Driver { func TestNeuroskyDriver(t *testing.T) { d := initTestNeuroskyDriver() - gobottest.Refute(t, d.Connection(), nil) + assert.NotNil(t, d.Connection()) } func TestNeuroskyDriverName(t *testing.T) { d := initTestNeuroskyDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Neurosky"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Neurosky")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestNeuroskyDriverStart(t *testing.T) { @@ -48,11 +48,11 @@ func TestNeuroskyDriverStart(t *testing.T) { d := NewDriver(a) e := errors.New("read error") _ = d.Once(d.Event(Error), func(data interface{}) { - gobottest.Assert(t, data.(error), e) + assert.Equal(t, e, data.(error)) sem <- true }) - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) time.Sleep(50 * time.Millisecond) rwc.ReadError(e) @@ -69,7 +69,7 @@ func TestNeuroskyDriverStart(t *testing.T) { func TestNeuroskyDriverHalt(t *testing.T) { d := initTestNeuroskyDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestNeuroskyDriverParse(t *testing.T) { @@ -99,7 +99,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(Signal), func(data interface{}) { - gobottest.Assert(t, data.(byte), byte(100)) + assert.Equal(t, byte(100), data.(byte)) sem <- true }) @@ -112,7 +112,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(Attention), func(data interface{}) { - gobottest.Assert(t, data.(byte), byte(40)) + assert.Equal(t, byte(40), data.(byte)) sem <- true }) @@ -125,7 +125,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(Meditation), func(data interface{}) { - gobottest.Assert(t, data.(byte), byte(60)) + assert.Equal(t, byte(60), data.(byte)) sem <- true }) @@ -138,7 +138,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(Blink), func(data interface{}) { - gobottest.Assert(t, data.(byte), byte(150)) + assert.Equal(t, byte(150), data.(byte)) sem <- true }) @@ -151,7 +151,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(Wave), func(data interface{}) { - gobottest.Assert(t, data.(int16), int16(16401)) + assert.Equal(t, int16(16401), data.(int16)) sem <- true }) @@ -166,8 +166,7 @@ func TestNeuroskyDriverParse(t *testing.T) { }() _ = d.On(d.Event(EEG), func(data interface{}) { - gobottest.Assert(t, - data.(EEGData), + assert.Equal(t, EEGData{ Delta: 1573241, Theta: 5832801, @@ -177,7 +176,8 @@ func TestNeuroskyDriverParse(t *testing.T) { HiBeta: 10485791, LoGamma: 8323090, MidGamma: 13565965, - }) + }, + data.(EEGData)) sem <- true }) <-sem diff --git a/platforms/opencv/camera_driver_test.go b/platforms/opencv/camera_driver_test.go index dd3ae7bf8..989c0e95e 100644 --- a/platforms/opencv/camera_driver_test.go +++ b/platforms/opencv/camera_driver_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*CameraDriver)(nil) @@ -22,21 +22,21 @@ func initTestCameraDriver() *CameraDriver { func TestCameraDriver(t *testing.T) { d := initTestCameraDriver() - gobottest.Assert(t, d.Name(), "Camera") - gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil)) + assert.Equal(t, "Camera", d.Name()) + assert.Equal(t, (gobot.Connection)(nil), d.Connection()) } func TestCameraDriverName(t *testing.T) { d := initTestCameraDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Camera"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Camera")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestCameraDriverStart(t *testing.T) { sem := make(chan bool) d := initTestCameraDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) d.On(d.Event("frame"), func(data interface{}) { sem <- true }) @@ -47,13 +47,13 @@ func TestCameraDriverStart(t *testing.T) { } d = NewCameraDriver("") - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) d = NewCameraDriver(true) - gobottest.Refute(t, d.Start(), nil) + assert.NotNil(t, d.Start()) } func TestCameraDriverHalt(t *testing.T) { d := initTestCameraDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } diff --git a/platforms/opencv/utils_test.go b/platforms/opencv/utils_test.go index b89a95c00..924dd53d7 100644 --- a/platforms/opencv/utils_test.go +++ b/platforms/opencv/utils_test.go @@ -5,7 +5,7 @@ import ( "runtime" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" "gocv.io/x/gocv" ) @@ -13,6 +13,6 @@ func TestUtils(t *testing.T) { _, currentfile, _, _ := runtime.Caller(0) image := gocv.IMRead(path.Join(path.Dir(currentfile), "lena-256x256.jpg"), gocv.IMReadColor) rect := DetectObjects("haarcascade_frontalface_alt.xml", image) - gobottest.Refute(t, len(rect), 0) + assert.NotEqual(t, 0, len(rect)) DrawRectangles(image, rect, 0, 0, 0, 0) } diff --git a/platforms/opencv/window_driver_test.go b/platforms/opencv/window_driver_test.go index 9a1127744..7d5d2acd5 100644 --- a/platforms/opencv/window_driver_test.go +++ b/platforms/opencv/window_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gocv.io/x/gocv" ) @@ -20,25 +20,25 @@ func initTestWindowDriver() *WindowDriver { func TestWindowDriver(t *testing.T) { d := initTestWindowDriver() - gobottest.Assert(t, d.Name(), "Window") - gobottest.Assert(t, d.Connection(), (gobot.Connection)(nil)) + assert.Equal(t, "Window", d.Name()) + assert.Equal(t, (gobot.Connection)(nil), d.Connection()) } func TestWindowDriverName(t *testing.T) { d := initTestWindowDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Window"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Window")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestWindowDriverStart(t *testing.T) { d := initTestWindowDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestWindowDriverHalt(t *testing.T) { d := initTestWindowDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestWindowDriverShowImage(t *testing.T) { diff --git a/platforms/parrot/ardrone/ardrone_adaptor_test.go b/platforms/parrot/ardrone/ardrone_adaptor_test.go index beb8ffe89..bcfd75357 100644 --- a/platforms/parrot/ardrone/ardrone_adaptor_test.go +++ b/platforms/parrot/ardrone/ardrone_adaptor_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -21,30 +21,30 @@ func initTestArdroneAdaptor() *Adaptor { func TestArdroneAdaptor(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.config.Ip, "192.168.1.1") + assert.Equal(t, "192.168.1.1", a.config.Ip) a = NewAdaptor("192.168.100.100") - gobottest.Assert(t, a.config.Ip, "192.168.100.100") + assert.Equal(t, "192.168.100.100", a.config.Ip) } func TestArdroneAdaptorConnect(t *testing.T) { a := initTestArdroneAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(a *Adaptor) (drone, error) { return nil, errors.New("connection error") } - gobottest.Assert(t, a.Connect(), errors.New("connection error")) + assert.Errorf(t, a.Connect(), "connection error") } func TestArdroneAdaptorName(t *testing.T) { a := initTestArdroneAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "ARDrone"), true) + assert.True(t, strings.HasPrefix(a.Name(), "ARDrone")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestArdroneAdaptorFinalize(t *testing.T) { a := initTestArdroneAdaptor() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } diff --git a/platforms/parrot/ardrone/ardrone_driver_test.go b/platforms/parrot/ardrone/ardrone_driver_test.go index dfdf6e26c..3f37b1d2d 100644 --- a/platforms/parrot/ardrone/ardrone_driver_test.go +++ b/platforms/parrot/ardrone/ardrone_driver_test.go @@ -3,8 +3,8 @@ package ardrone import ( "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -22,24 +22,24 @@ func initTestArdroneDriver() *Driver { func TestArdroneDriver(t *testing.T) { d := initTestArdroneDriver() - gobottest.Assert(t, d.Name(), "mydrone") + assert.Equal(t, "mydrone", d.Name()) } func TestArdroneDriverName(t *testing.T) { d := initTestArdroneDriver() - gobottest.Assert(t, d.Name(), "mydrone") + assert.Equal(t, "mydrone", d.Name()) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestArdroneDriverStart(t *testing.T) { d := initTestArdroneDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestArdroneDriverHalt(t *testing.T) { d := initTestArdroneDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestArdroneDriverTakeOff(t *testing.T) { d := initTestArdroneDriver() diff --git a/platforms/parrot/ardrone/pitch_test.go b/platforms/parrot/ardrone/pitch_test.go index 97e3ac9ae..c4f5870c2 100644 --- a/platforms/parrot/ardrone/pitch_test.go +++ b/platforms/parrot/ardrone/pitch_test.go @@ -3,17 +3,17 @@ package ardrone import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestArdroneValidatePitchWhenEqualOffset(t *testing.T) { - gobottest.Assert(t, ValidatePitch(32767.0, 32767.0), 1.0) + assert.Equal(t, 1.0, ValidatePitch(32767.0, 32767.0)) } func TestArdroneValidatePitchWhenTiny(t *testing.T) { - gobottest.Assert(t, ValidatePitch(1.1, 32767.0), 0.0) + assert.Equal(t, 0.0, ValidatePitch(1.1, 32767.0)) } func TestArdroneValidatePitchWhenCentered(t *testing.T) { - gobottest.Assert(t, ValidatePitch(16383.5, 32767.0), 0.5) + assert.Equal(t, 0.5, ValidatePitch(16383.5, 32767.0)) } diff --git a/platforms/parrot/bebop/bebop_adaptor_test.go b/platforms/parrot/bebop/bebop_adaptor_test.go index 7faf839ca..a2ebba5ef 100644 --- a/platforms/parrot/bebop/bebop_adaptor_test.go +++ b/platforms/parrot/bebop/bebop_adaptor_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -22,23 +22,23 @@ func initTestBebopAdaptor() *Adaptor { func TestBebopAdaptorName(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Bebop"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Bebop")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestBebopAdaptorConnect(t *testing.T) { a := initTestBebopAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(a *Adaptor) error { return errors.New("connection error") } - gobottest.Assert(t, a.Connect(), errors.New("connection error")) + assert.Errorf(t, a.Connect(), "connection error") } func TestBebopAdaptorFinalize(t *testing.T) { a := initTestBebopAdaptor() _ = a.Connect() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } diff --git a/platforms/parrot/bebop/bebop_driver_test.go b/platforms/parrot/bebop/bebop_driver_test.go index 0565114ba..6685eb650 100644 --- a/platforms/parrot/bebop/bebop_driver_test.go +++ b/platforms/parrot/bebop/bebop_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -13,7 +13,7 @@ var _ gobot.Driver = (*Driver)(nil) func TestBebopDriverName(t *testing.T) { a := initTestBebopAdaptor() d := NewDriver(a) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Bebop"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Bebop")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } diff --git a/platforms/parrot/bebop/pitch_test.go b/platforms/parrot/bebop/pitch_test.go index 62dc13980..bf119f347 100644 --- a/platforms/parrot/bebop/pitch_test.go +++ b/platforms/parrot/bebop/pitch_test.go @@ -3,17 +3,17 @@ package bebop import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestBebopValidatePitchWhenEqualOffset(t *testing.T) { - gobottest.Assert(t, ValidatePitch(32767.0, 32767.0), 100) + assert.Equal(t, 100, ValidatePitch(32767.0, 32767.0)) } func TestBebopValidatePitchWhenTiny(t *testing.T) { - gobottest.Assert(t, ValidatePitch(1.1, 32767.0), 0) + assert.Equal(t, 0, ValidatePitch(1.1, 32767.0)) } func TestBebopValidatePitchWhenCentered(t *testing.T) { - gobottest.Assert(t, ValidatePitch(16383.5, 32767.0), 50) + assert.Equal(t, 50, ValidatePitch(16383.5, 32767.0)) } diff --git a/platforms/parrot/minidrone/minidrone_driver_test.go b/platforms/parrot/minidrone/minidrone_driver_test.go index d57a65ae2..5ab313a45 100644 --- a/platforms/parrot/minidrone/minidrone_driver_test.go +++ b/platforms/parrot/minidrone/minidrone_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -17,154 +17,154 @@ func initTestMinidroneDriver() *Driver { func TestMinidroneDriver(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Minidrone"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Minidrone")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestMinidroneDriverStartAndHalt(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestMinidroneTakeoff(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.TakeOff(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.TakeOff()) } func TestMinidroneEmergency(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Emergency(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Emergency()) } func TestMinidroneTakePicture(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.TakePicture(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.TakePicture()) } func TestMinidroneUp(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Up(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Up(25)) } func TestMinidroneUpTooFar(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Up(125), nil) - gobottest.Assert(t, d.Up(-50), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Up(125)) + assert.Nil(t, d.Up(-50)) } func TestMinidroneDown(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Down(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Down(25)) } func TestMinidroneForward(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Forward(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Forward(25)) } func TestMinidroneBackward(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Backward(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Backward(25)) } func TestMinidroneRight(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Right(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Right(25)) } func TestMinidroneLeft(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Left(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Left(25)) } func TestMinidroneClockwise(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Clockwise(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Clockwise(25)) } func TestMinidroneCounterClockwise(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.CounterClockwise(25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.CounterClockwise(25)) } func TestMinidroneStop(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Stop(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Stop()) } func TestMinidroneStartStopRecording(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.StartRecording(), nil) - gobottest.Assert(t, d.StopRecording(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.StartRecording()) + assert.Nil(t, d.StopRecording()) } func TestMinidroneHullProtectionOutdoor(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.HullProtection(true), nil) - gobottest.Assert(t, d.Outdoor(true), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.HullProtection(true)) + assert.Nil(t, d.Outdoor(true)) } func TestMinidroneHullFlips(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.FrontFlip(), nil) - gobottest.Assert(t, d.BackFlip(), nil) - gobottest.Assert(t, d.RightFlip(), nil) - gobottest.Assert(t, d.LeftFlip(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.FrontFlip()) + assert.Nil(t, d.BackFlip()) + assert.Nil(t, d.RightFlip()) + assert.Nil(t, d.LeftFlip()) } func TestMinidroneLightControl(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.LightControl(0, LightBlinked, 25), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.LightControl(0, LightBlinked, 25)) } func TestMinidroneClawControl(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.ClawControl(0, ClawOpen), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.ClawControl(0, ClawOpen)) } func TestMinidroneGunControl(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.GunControl(0), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.GunControl(0)) } func TestMinidroneProcessFlightData(t *testing.T) { d := initTestMinidroneDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) d.processFlightStatus([]byte{0x00, 0x00, 0x00}) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x00}) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}) - gobottest.Assert(t, d.flying, false) + assert.False(t, d.flying) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01}) - gobottest.Assert(t, d.flying, false) + assert.False(t, d.flying) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}) - gobottest.Assert(t, d.flying, true) + assert.True(t, d.flying) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03}) - gobottest.Assert(t, d.flying, true) + assert.True(t, d.flying) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04}) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05}) d.processFlightStatus([]byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06}) - gobottest.Assert(t, d.Stop(), nil) + assert.Nil(t, d.Stop()) } diff --git a/platforms/parrot/minidrone/pitch_test.go b/platforms/parrot/minidrone/pitch_test.go index 8b0261715..51b838bed 100644 --- a/platforms/parrot/minidrone/pitch_test.go +++ b/platforms/parrot/minidrone/pitch_test.go @@ -3,17 +3,17 @@ package minidrone import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestMinidroneValidatePitchWhenEqualOffset(t *testing.T) { - gobottest.Assert(t, ValidatePitch(32767.0, 32767.0), 100) + assert.Equal(t, 100, ValidatePitch(32767.0, 32767.0)) } func TestMinidroneValidatePitchWhenTiny(t *testing.T) { - gobottest.Assert(t, ValidatePitch(1.1, 32767.0), 0) + assert.Equal(t, 0, ValidatePitch(1.1, 32767.0)) } func TestMinidroneValidatePitchWhenCentered(t *testing.T) { - gobottest.Assert(t, ValidatePitch(16383.5, 32767.0), 50) + assert.Equal(t, 50, ValidatePitch(16383.5, 32767.0)) } diff --git a/platforms/particle/adaptor_test.go b/platforms/particle/adaptor_test.go index 0c55db12e..e1e028a53 100644 --- a/platforms/particle/adaptor_test.go +++ b/platforms/particle/adaptor_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/donovanhide/eventsource" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) // HELPERS @@ -79,22 +79,22 @@ func TestNewAdaptor(t *testing.T) { t.Errorf("NewAdaptor() should have returned a *Adaptor") } - gobottest.Assert(t, core.APIServer, "https://api.particle.io") - gobottest.Assert(t, strings.HasPrefix(core.Name(), "Particle"), true) + assert.Equal(t, "https://api.particle.io", core.APIServer) + assert.True(t, strings.HasPrefix(core.Name(), "Particle")) core.SetName("sparkie") - gobottest.Assert(t, core.Name(), "sparkie") + assert.Equal(t, "sparkie", core.Name()) } func TestAdaptorConnect(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) } func TestAdaptorFinalize(t *testing.T) { a := initTestAdaptor() _ = a.Connect() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestAdaptorAnalogRead(t *testing.T) { @@ -109,7 +109,7 @@ func TestAdaptorAnalogRead(t *testing.T) { defer testServer.Close() val, _ := a.AnalogRead("A1") - gobottest.Assert(t, val, 5) + assert.Equal(t, 5, val) } func TestAdaptorAnalogReadError(t *testing.T) { @@ -122,7 +122,7 @@ func TestAdaptorAnalogReadError(t *testing.T) { a.setAPIServer(testServer.URL) val, _ := a.AnalogRead("A1") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) } func TestAdaptorPwmWrite(t *testing.T) { @@ -206,7 +206,7 @@ func TestAdaptorDigitalRead(t *testing.T) { a.setAPIServer(testServer.URL) val, _ := a.DigitalRead("D7") - gobottest.Assert(t, val, 1) + assert.Equal(t, 1, val) testServer.Close() // When LOW @@ -218,7 +218,7 @@ func TestAdaptorDigitalRead(t *testing.T) { defer testServer.Close() val, _ = a.DigitalRead("D7") - gobottest.Assert(t, val, 0) + assert.Equal(t, 0, val) } func TestAdaptorDigitalReadError(t *testing.T) { @@ -232,7 +232,7 @@ func TestAdaptorDigitalReadError(t *testing.T) { a.setAPIServer(testServer.URL) val, _ := a.DigitalRead("D7") - gobottest.Assert(t, val, -1) + assert.Equal(t, -1, val) } func TestAdaptorFunction(t *testing.T) { @@ -244,7 +244,7 @@ func TestAdaptorFunction(t *testing.T) { a.setAPIServer(testServer.URL) val, _ := a.Function("hello", "100,200") - gobottest.Assert(t, val, 1) + assert.Equal(t, 1, val) testServer.Close() // When not existent @@ -254,7 +254,7 @@ func TestAdaptorFunction(t *testing.T) { a.setAPIServer(testServer.URL) _, err := a.Function("hello", "") - gobottest.Assert(t, err.Error(), "timeout") + assert.Errorf(t, err, "timeout") testServer.Close() } @@ -269,7 +269,7 @@ func TestAdaptorVariable(t *testing.T) { a.setAPIServer(testServer.URL) val, _ := a.Variable("variable_name") - gobottest.Assert(t, val, "1") + assert.Equal(t, "1", val) testServer.Close() // When float @@ -279,7 +279,7 @@ func TestAdaptorVariable(t *testing.T) { a.setAPIServer(testServer.URL) val, _ = a.Variable("variable_name") - gobottest.Assert(t, val, "1.1") + assert.Equal(t, "1.1", val) testServer.Close() // When int @@ -289,7 +289,7 @@ func TestAdaptorVariable(t *testing.T) { a.setAPIServer(testServer.URL) val, _ = a.Variable("variable_name") - gobottest.Assert(t, val, "1") + assert.Equal(t, "1", val) testServer.Close() // When bool @@ -299,7 +299,7 @@ func TestAdaptorVariable(t *testing.T) { a.setAPIServer(testServer.URL) val, _ = a.Variable("variable_name") - gobottest.Assert(t, val, "true") + assert.Equal(t, "true", val) testServer.Close() // When not existent @@ -309,7 +309,7 @@ func TestAdaptorVariable(t *testing.T) { a.setAPIServer(testServer.URL) _, err := a.Variable("not_existent") - gobottest.Assert(t, err.Error(), "Variable not found") + assert.Errorf(t, err, "Variable not found") testServer.Close() } @@ -317,10 +317,10 @@ func TestAdaptorVariable(t *testing.T) { func TestAdaptorSetAPIServer(t *testing.T) { a := initTestAdaptor() apiServer := "new_api_server" - gobottest.Refute(t, a.APIServer, apiServer) + assert.NotEqual(t, apiServer, a.APIServer) a.setAPIServer(apiServer) - gobottest.Assert(t, a.APIServer, apiServer) + assert.Equal(t, apiServer, a.APIServer) } func TestAdaptorDeviceURL(t *testing.T) { @@ -328,19 +328,19 @@ func TestAdaptorDeviceURL(t *testing.T) { a := initTestAdaptor() a.setAPIServer("http://server") a.DeviceID = "devID" - gobottest.Assert(t, a.deviceURL(), "http://server/v1/devices/devID") + assert.Equal(t, "http://server/v1/devices/devID", a.deviceURL()) // When APIServer is not set a = &Adaptor{name: "particleie", DeviceID: "myDevice", AccessToken: "token"} - gobottest.Assert(t, a.deviceURL(), "https://api.particle.io/v1/devices/myDevice") + assert.Equal(t, "https://api.particle.io/v1/devices/myDevice", a.deviceURL()) } func TestAdaptorPinLevel(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, a.pinLevel(1), "HIGH") - gobottest.Assert(t, a.pinLevel(0), "LOW") - gobottest.Assert(t, a.pinLevel(5), "LOW") + assert.Equal(t, "HIGH", a.pinLevel(1)) + assert.Equal(t, "LOW", a.pinLevel(0)) + assert.Equal(t, "LOW", a.pinLevel(5)) } func TestAdaptorPostToparticle(t *testing.T) { @@ -377,23 +377,23 @@ func TestAdaptorEventStream(t *testing.T) { return nil, nil, nil } _, _ = a.EventStream("all", "ping") - gobottest.Assert(t, url, "https://api.particle.io/v1/events/ping?access_token=token") + assert.Equal(t, "https://api.particle.io/v1/events/ping?access_token=token", url) _, _ = a.EventStream("devices", "ping") - gobottest.Assert(t, url, "https://api.particle.io/v1/devices/events/ping?access_token=token") + assert.Equal(t, "https://api.particle.io/v1/devices/events/ping?access_token=token", url) _, _ = a.EventStream("device", "ping") - gobottest.Assert(t, url, "https://api.particle.io/v1/devices/myDevice/events/ping?access_token=token") + assert.Equal(t, "https://api.particle.io/v1/devices/myDevice/events/ping?access_token=token", url) _, err := a.EventStream("nothing", "ping") - gobottest.Assert(t, err.Error(), "source param should be: all, devices or device") + assert.Errorf(t, err, "source param should be: all, devices or device") eventSource = func(u string) (chan eventsource.Event, chan error, error) { return nil, nil, errors.New("error connecting sse") } _, err = a.EventStream("devices", "") - gobottest.Assert(t, err.Error(), "error connecting sse") + assert.Errorf(t, err, "error connecting sse") eventChan := make(chan eventsource.Event) errorChan := make(chan error) @@ -403,5 +403,5 @@ func TestAdaptorEventStream(t *testing.T) { } _, err = a.EventStream("devices", "") - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } diff --git a/platforms/pebble/pebble_adaptor_test.go b/platforms/pebble/pebble_adaptor_test.go index 2ae333ab6..e15597863 100644 --- a/platforms/pebble/pebble_adaptor_test.go +++ b/platforms/pebble/pebble_adaptor_test.go @@ -3,8 +3,8 @@ package pebble import ( "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -15,14 +15,14 @@ func initTestAdaptor() *Adaptor { func TestAdaptor(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, a.Name(), "Pebble") + assert.Equal(t, "Pebble", a.Name()) } func TestAdaptorConnect(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) } func TestAdaptorFinalize(t *testing.T) { a := initTestAdaptor() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } diff --git a/platforms/pebble/pebble_driver_test.go b/platforms/pebble/pebble_driver_test.go index cbf0cd695..997afe9b6 100644 --- a/platforms/pebble/pebble_driver_test.go +++ b/platforms/pebble/pebble_driver_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*Driver)(nil) @@ -16,28 +16,28 @@ func initTestDriver() *Driver { func TestDriverStart(t *testing.T) { d := initTestDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestDriverHalt(t *testing.T) { d := initTestDriver() - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestDriver(t *testing.T) { d := initTestDriver() - gobottest.Assert(t, d.Name(), "Pebble") - gobottest.Assert(t, d.Connection().Name(), "Pebble") + assert.Equal(t, "Pebble", d.Name()) + assert.Equal(t, "Pebble", d.Connection().Name()) sem := make(chan bool) d.SendNotification("Hello") d.SendNotification("World") - gobottest.Assert(t, d.Messages[0], "Hello") - gobottest.Assert(t, d.PendingMessage(), "Hello") - gobottest.Assert(t, d.PendingMessage(), "World") - gobottest.Assert(t, d.PendingMessage(), "") + assert.Equal(t, "Hello", d.Messages[0]) + assert.Equal(t, "Hello", d.PendingMessage()) + assert.Equal(t, "World", d.PendingMessage()) + assert.Equal(t, "", d.PendingMessage()) _ = d.On(d.Event("button"), func(data interface{}) { sem <- true @@ -64,8 +64,8 @@ func TestDriver(t *testing.T) { } d.Command("send_notification")(map[string]interface{}{"message": "Hey buddy!"}) - gobottest.Assert(t, d.Messages[0], "Hey buddy!") + assert.Equal(t, "Hey buddy!", d.Messages[0]) message := d.Command("pending_message")(map[string]interface{}{}) - gobottest.Assert(t, message, "Hey buddy!") + assert.Equal(t, "Hey buddy!", message) } diff --git a/platforms/raspi/pwm_pin_test.go b/platforms/raspi/pwm_pin_test.go index df0cc2f6c..080d4a862 100644 --- a/platforms/raspi/pwm_pin_test.go +++ b/platforms/raspi/pwm_pin_test.go @@ -1,11 +1,10 @@ package raspi import ( - "errors" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -18,37 +17,37 @@ func TestPwmPin(t *testing.T) { pin := NewPWMPin(a, path, "1") - gobottest.Assert(t, pin.Export(), nil) - gobottest.Assert(t, pin.SetEnabled(true), nil) + assert.Nil(t, pin.Export()) + assert.Nil(t, pin.SetEnabled(true)) val, _ := pin.Polarity() - gobottest.Assert(t, val, true) + assert.True(t, val) - gobottest.Assert(t, pin.SetPolarity(false), nil) + assert.Nil(t, pin.SetPolarity(false)) val, _ = pin.Polarity() - gobottest.Assert(t, val, true) + assert.True(t, val) _, err := pin.Period() - gobottest.Assert(t, err, errors.New("Raspi PWM pin period not set")) - gobottest.Assert(t, pin.SetDutyCycle(10000), errors.New("Raspi PWM pin period not set")) + assert.Errorf(t, err, "Raspi PWM pin period not set") + assert.Errorf(t, pin.SetDutyCycle(10000), "Raspi PWM pin period not set") - gobottest.Assert(t, pin.SetPeriod(20000000), nil) + assert.Nil(t, pin.SetPeriod(20000000)) period, _ := pin.Period() - gobottest.Assert(t, period, uint32(20000000)) - gobottest.Assert(t, pin.SetPeriod(10000000), errors.New("Cannot set the period of individual PWM pins on Raspi")) + assert.Equal(t, uint32(20000000), period) + assert.Errorf(t, pin.SetPeriod(10000000), "Cannot set the period of individual PWM pins on Raspi") dc, _ := pin.DutyCycle() - gobottest.Assert(t, dc, uint32(0)) + assert.Equal(t, uint32(0), dc) - gobottest.Assert(t, pin.SetDutyCycle(10000), nil) + assert.Nil(t, pin.SetDutyCycle(10000)) dc, _ = pin.DutyCycle() - gobottest.Assert(t, dc, uint32(10000)) + assert.Equal(t, uint32(10000), dc) - gobottest.Assert(t, pin.SetDutyCycle(999999999), errors.New("Duty cycle exceeds period")) + assert.Errorf(t, pin.SetDutyCycle(999999999), "Duty cycle exceeds period") dc, _ = pin.DutyCycle() - gobottest.Assert(t, dc, uint32(10000)) + assert.Equal(t, uint32(10000), dc) - gobottest.Assert(t, pin.Unexport(), nil) + assert.Nil(t, pin.Unexport()) } diff --git a/platforms/raspi/raspi_adaptor_test.go b/platforms/raspi/raspi_adaptor_test.go index 560fed662..f73e3f2df 100644 --- a/platforms/raspi/raspi_adaptor_test.go +++ b/platforms/raspi/raspi_adaptor_test.go @@ -1,7 +1,6 @@ package raspi import ( - "errors" "fmt" "strings" "testing" @@ -10,11 +9,11 @@ import ( "strconv" "sync" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" "gobot.io/x/gobot/v2/drivers/spi" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -39,9 +38,9 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestName(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "RaspberryPi"), true) + assert.True(t, strings.HasPrefix(a.Name(), "RaspberryPi")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestGetDefaultBus(t *testing.T) { @@ -77,12 +76,12 @@ func TestGetDefaultBus(t *testing.T) { a := NewAdaptor() fs := a.sys.UseMockFilesystem([]string{infoFile}) fs.Files[infoFile].Contents = fmt.Sprintf(contentPattern, tc.revisionPart) - gobottest.Assert(t, a.revision, "") + assert.Equal(t, "", a.revision) //act, will read and refresh the revision gotBus := a.DefaultI2cBus() //assert - gobottest.Assert(t, a.revision, tc.wantRev) - gobottest.Assert(t, gotBus, tc.wantBus) + assert.Equal(t, tc.wantRev, a.revision) + assert.Equal(t, tc.wantBus, gotBus) }) } } @@ -103,7 +102,7 @@ func TestFinalize(t *testing.T) { _ = a.PwmWrite("7", 255) _, _ = a.GetI2cConnection(0xff, 0) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestDigitalPWM(t *testing.T) { @@ -111,30 +110,30 @@ func TestDigitalPWM(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(mockedPaths) a.PiBlasterPeriod = 20000000 - gobottest.Assert(t, a.PwmWrite("7", 4), nil) + assert.Nil(t, a.PwmWrite("7", 4)) pin, _ := a.PWMPin("7") period, _ := pin.Period() - gobottest.Assert(t, period, uint32(20000000)) + assert.Equal(t, uint32(20000000), period) - gobottest.Assert(t, a.PwmWrite("7", 255), nil) + assert.Nil(t, a.PwmWrite("7", 255)) - gobottest.Assert(t, strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0], "4=1") + assert.Equal(t, "4=1", strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0]) - gobottest.Assert(t, a.ServoWrite("11", 90), nil) + assert.Nil(t, a.ServoWrite("11", 90)) - gobottest.Assert(t, strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0], "17=0.5") + assert.Equal(t, "17=0.5", strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0]) - gobottest.Assert(t, a.PwmWrite("notexist", 1), errors.New("Not a valid pin")) - gobottest.Assert(t, a.ServoWrite("notexist", 1), errors.New("Not a valid pin")) + assert.Errorf(t, a.PwmWrite("notexist", 1), "Not a valid pin") + assert.Errorf(t, a.ServoWrite("notexist", 1), "Not a valid pin") pin, _ = a.PWMPin("12") period, _ = pin.Period() - gobottest.Assert(t, period, uint32(20000000)) + assert.Equal(t, uint32(20000000), period) - gobottest.Assert(t, pin.SetDutyCycle(1.5*1000*1000), nil) + assert.Nil(t, pin.SetDutyCycle(1.5*1000*1000)) - gobottest.Assert(t, strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0], "18=0.075") + assert.Equal(t, "18=0.075", strings.Split(fs.Files["/dev/pi-blaster"].Contents, "\n")[0]) } func TestDigitalIO(t *testing.T) { @@ -149,19 +148,19 @@ func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(mockedPaths) err := a.DigitalWrite("7", 1) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio4/value"].Contents, "1") + assert.Nil(t, err) + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio4/value"].Contents) a.revision = "2" err = a.DigitalWrite("13", 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) i, err := a.DigitalRead("13") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, i, 1) + assert.Nil(t, err) + assert.Equal(t, 1, i) - gobottest.Assert(t, a.DigitalWrite("notexist", 1), errors.New("Not a valid pin")) - gobottest.Assert(t, a.Finalize(), nil) + assert.Errorf(t, a.DigitalWrite("notexist", 1), "Not a valid pin") + assert.Nil(t, a.Finalize()) } func TestDigitalPinConcurrency(t *testing.T) { @@ -193,24 +192,24 @@ func TestPWMPin(t *testing.T) { panic(err) } - gobottest.Assert(t, len(a.pwmPins), 0) + assert.Equal(t, 0, len(a.pwmPins)) a.revision = "3" firstSysPin, err := a.PWMPin("35") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 1) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.pwmPins)) secondSysPin, err := a.PWMPin("35") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 1) - gobottest.Assert(t, firstSysPin, secondSysPin) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.pwmPins)) + assert.Equal(t, secondSysPin, firstSysPin) otherSysPin, err := a.PWMPin("36") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 2) - gobottest.Refute(t, firstSysPin, otherSysPin) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.pwmPins)) + assert.NotEqual(t, otherSysPin, firstSysPin) } func TestPWMPinsReConnect(t *testing.T) { @@ -222,27 +221,27 @@ func TestPWMPinsReConnect(t *testing.T) { } _, err := a.PWMPin("35") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 1) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, err) + assert.Equal(t, 1, len(a.pwmPins)) + assert.Nil(t, a.Finalize()) // act err = a.Connect() // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 0) + assert.Nil(t, err) + assert.Equal(t, 0, len(a.pwmPins)) _, _ = a.PWMPin("35") _, err = a.PWMPin("36") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, len(a.pwmPins), 2) + assert.Nil(t, err) + assert.Equal(t, 2, len(a.pwmPins)) } func TestSpiDefaultValues(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.SpiDefaultBusNumber(), 0) - gobottest.Assert(t, a.SpiDefaultChipNumber(), 0) - gobottest.Assert(t, a.SpiDefaultMode(), 0) - gobottest.Assert(t, a.SpiDefaultMaxSpeed(), int64(500000)) + assert.Equal(t, 0, a.SpiDefaultBusNumber()) + assert.Equal(t, 0, a.SpiDefaultChipNumber()) + assert.Equal(t, 0, a.SpiDefaultMode()) + assert.Equal(t, int64(500000), a.SpiDefaultMaxSpeed()) } func TestI2cDefaultBus(t *testing.T) { @@ -251,10 +250,10 @@ func TestI2cDefaultBus(t *testing.T) { a.sys.UseMockSyscall() a.revision = "0" - gobottest.Assert(t, a.DefaultI2cBus(), 0) + assert.Equal(t, 0, a.DefaultI2cBus()) a.revision = "2" - gobottest.Assert(t, a.DefaultI2cBus(), 1) + assert.Equal(t, 1, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -262,16 +261,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-1"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 1) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateSpiBusNumber(t *testing.T) { @@ -301,7 +300,7 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -333,7 +332,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } diff --git a/platforms/rockpi/rockpi_adaptor_test.go b/platforms/rockpi/rockpi_adaptor_test.go index 1e3186298..121777a13 100644 --- a/platforms/rockpi/rockpi_adaptor_test.go +++ b/platforms/rockpi/rockpi_adaptor_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2/system" ) @@ -17,7 +17,7 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestDefaultI2cBus(t *testing.T) { a, _ := initTestAdaptorWithMockedFilesystem([]string{}) - gobottest.Assert(t, a.DefaultI2cBus(), 7) + assert.Equal(t, 7, a.DefaultI2cBus()) } func Test_getPinTranslatorFunction(t *testing.T) { @@ -63,9 +63,9 @@ func Test_getPinTranslatorFunction(t *testing.T) { // act chip, line, err := fn(tc.pin) // assert - gobottest.Assert(t, chip, "") - gobottest.Assert(t, err, tc.expectedErr) - gobottest.Assert(t, line, tc.expectedLine) + assert.Equal(t, "", chip) + assert.Equal(t, tc.expectedErr, err) + assert.Equal(t, tc.expectedLine, line) }) } } @@ -97,7 +97,7 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.expectedErr) + assert.Equal(t, tc.expectedErr, err) }) } } @@ -132,7 +132,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } diff --git a/platforms/sphero/bb8/bb8_driver_test.go b/platforms/sphero/bb8/bb8_driver_test.go index a56ed5155..e5ed22afa 100644 --- a/platforms/sphero/bb8/bb8_driver_test.go +++ b/platforms/sphero/bb8/bb8_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*BB8Driver)(nil) @@ -17,13 +17,13 @@ func initTestBB8Driver() *BB8Driver { func TestBB8Driver(t *testing.T) { d := initTestBB8Driver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "BB8"), true) + assert.True(t, strings.HasPrefix(d.Name(), "BB8")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestBB8DriverStartAndHalt(t *testing.T) { d := initTestBB8Driver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } diff --git a/platforms/sphero/ollie/ollie_driver_test.go b/platforms/sphero/ollie/ollie_driver_test.go index 847c48dcf..472cc55bf 100644 --- a/platforms/sphero/ollie/ollie_driver_test.go +++ b/platforms/sphero/ollie/ollie_driver_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/platforms/sphero" ) @@ -21,13 +21,13 @@ func initTestOllieDriver() *Driver { func TestOllieDriver(t *testing.T) { d := initTestOllieDriver() d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestOllieDriverStartAndHalt(t *testing.T) { d := initTestOllieDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } func TestLocatorData(t *testing.T) { @@ -53,7 +53,7 @@ func TestLocatorData(t *testing.T) { packet := []byte{0xFF, 0xFF, 0x00, 0x00, 0x0B, point.x1, point.x2, point.y1, point.y2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} d.GetLocatorData(func(p Point2D) { - gobottest.Assert(t, p.Y, point.y) + assert.Equal(t, point.y, p.Y) }) d.HandleResponses(packet, nil) } @@ -68,7 +68,7 @@ func TestDataStreaming(t *testing.T) { _ = d.On("sensordata", func(data interface{}) { cont := data.(DataStreamingPacket) fmt.Printf("got streaming packet: %+v \n", cont) - gobottest.Assert(t, cont.RawAccX, int16(10)) + assert.Equal(t, int16(10), cont.RawAccX) response = true }) diff --git a/platforms/sphero/sphero_adaptor_test.go b/platforms/sphero/sphero_adaptor_test.go index cd9403359..ea9224a9f 100644 --- a/platforms/sphero/sphero_adaptor_test.go +++ b/platforms/sphero/sphero_adaptor_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Adaptor = (*Adaptor)(nil) @@ -56,49 +56,49 @@ func initTestSpheroAdaptor() (*Adaptor, *nullReadWriteCloser) { func TestSpheroAdaptorName(t *testing.T) { a, _ := initTestSpheroAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Sphero"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Sphero")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestSpheroAdaptor(t *testing.T) { a, _ := initTestSpheroAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Sphero"), true) - gobottest.Assert(t, a.Port(), "/dev/null") + assert.True(t, strings.HasPrefix(a.Name(), "Sphero")) + assert.Equal(t, "/dev/null", a.Port()) } func TestSpheroAdaptorReconnect(t *testing.T) { a, _ := initTestSpheroAdaptor() _ = a.Connect() - gobottest.Assert(t, a.connected, true) + assert.True(t, a.connected) _ = a.Reconnect() - gobottest.Assert(t, a.connected, true) + assert.True(t, a.connected) _ = a.Disconnect() - gobottest.Assert(t, a.connected, false) + assert.False(t, a.connected) _ = a.Reconnect() - gobottest.Assert(t, a.connected, true) + assert.True(t, a.connected) } func TestSpheroAdaptorFinalize(t *testing.T) { a, rwc := initTestSpheroAdaptor() _ = a.Connect() - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) rwc.testAdaptorClose = func() error { return errors.New("close error") } a.connected = true - gobottest.Assert(t, a.Finalize(), errors.New("close error")) + assert.Errorf(t, a.Finalize(), "close error") } func TestSpheroAdaptorConnect(t *testing.T) { a, _ := initTestSpheroAdaptor() - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) a.connect = func(string) (io.ReadWriteCloser, error) { return nil, errors.New("connect error") } - gobottest.Assert(t, a.Connect(), errors.New("connect error")) + assert.Errorf(t, a.Connect(), "connect error") } diff --git a/platforms/sphero/sphero_driver_test.go b/platforms/sphero/sphero_driver_test.go index 28a3d79f7..a3d5df1ca 100644 --- a/platforms/sphero/sphero_driver_test.go +++ b/platforms/sphero/sphero_driver_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*SpheroDriver)(nil) @@ -20,9 +20,9 @@ func initTestSpheroDriver() *SpheroDriver { func TestSpheroDriverName(t *testing.T) { d := initTestSpheroDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Sphero"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Sphero")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestSpheroDriver(t *testing.T) { @@ -32,65 +32,65 @@ func TestSpheroDriver(t *testing.T) { ret = d.Command("SetRGB")( map[string]interface{}{"r": 100.0, "g": 100.0, "b": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("Roll")( map[string]interface{}{"speed": 100.0, "heading": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("SetBackLED")( map[string]interface{}{"level": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("ConfigureLocator")( map[string]interface{}{"Flags": 1.0, "X": 100.0, "Y": 100.0, "YawTare": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("SetHeading")( map[string]interface{}{"heading": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("SetRotationRate")( map[string]interface{}{"level": 100.0}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("SetStabilization")( map[string]interface{}{"enable": true}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("SetStabilization")( map[string]interface{}{"enable": false}, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("Stop")(nil) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) ret = d.Command("GetRGB")(nil) - gobottest.Assert(t, ret.([]byte), []byte{}) + assert.Equal(t, []byte{}, ret.([]byte)) ret = d.Command("ReadLocator")(nil) - gobottest.Assert(t, ret, []int16{}) + assert.Equal(t, []int16{}, ret) - gobottest.Assert(t, strings.HasPrefix(d.Name(), "Sphero"), true) - gobottest.Assert(t, strings.HasPrefix(d.Connection().Name(), "Sphero"), true) + assert.True(t, strings.HasPrefix(d.Name(), "Sphero")) + assert.True(t, strings.HasPrefix(d.Connection().Name(), "Sphero")) } func TestSpheroDriverStart(t *testing.T) { d := initTestSpheroDriver() - gobottest.Assert(t, d.Start(), nil) + assert.Nil(t, d.Start()) } func TestSpheroDriverHalt(t *testing.T) { d := initTestSpheroDriver() d.adaptor().connected = true - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Halt()) } func TestSpheroDriverSetDataStreaming(t *testing.T) { @@ -102,7 +102,7 @@ func TestSpheroDriverSetDataStreaming(t *testing.T) { buf := new(bytes.Buffer) _ = binary.Write(buf, binary.BigEndian, DefaultDataStreamingConfig()) - gobottest.Assert(t, data.body, buf.Bytes()) + assert.Equal(t, buf.Bytes(), data.body) ret := d.Command("SetDataStreaming")( map[string]interface{}{ @@ -113,14 +113,14 @@ func TestSpheroDriverSetDataStreaming(t *testing.T) { "Mask2": 400.0, }, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) data = <-d.packetChannel dconfig := DataStreamingConfig{N: 100, M: 200, Mask: 300, Pcnt: 255, Mask2: 400} buf = new(bytes.Buffer) _ = binary.Write(buf, binary.BigEndian, dconfig) - gobottest.Assert(t, data.body, buf.Bytes()) + assert.Equal(t, buf.Bytes(), data.body) } func TestConfigureLocator(t *testing.T) { @@ -131,7 +131,7 @@ func TestConfigureLocator(t *testing.T) { buf := new(bytes.Buffer) _ = binary.Write(buf, binary.BigEndian, DefaultLocatorConfig()) - gobottest.Assert(t, data.body, buf.Bytes()) + assert.Equal(t, buf.Bytes(), data.body) ret := d.Command("ConfigureLocator")( map[string]interface{}{ @@ -141,14 +141,14 @@ func TestConfigureLocator(t *testing.T) { "YawTare": 0.0, }, ) - gobottest.Assert(t, ret, nil) + assert.Nil(t, ret) data = <-d.packetChannel lconfig := LocatorConfig{Flags: 1, X: 100, Y: 100, YawTare: 0} buf = new(bytes.Buffer) _ = binary.Write(buf, binary.BigEndian, lconfig) - gobottest.Assert(t, data.body, buf.Bytes()) + assert.Equal(t, buf.Bytes(), data.body) } func TestCalculateChecksum(t *testing.T) { diff --git a/platforms/sphero/sprkplus/sprkplus_driver_test.go b/platforms/sphero/sprkplus/sprkplus_driver_test.go index 6bb1ed2d2..0c28c86ea 100644 --- a/platforms/sphero/sprkplus/sprkplus_driver_test.go +++ b/platforms/sphero/sprkplus/sprkplus_driver_test.go @@ -4,8 +4,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.Driver = (*SPRKPlusDriver)(nil) @@ -17,13 +17,13 @@ func initTestSPRKPlusDriver() *SPRKPlusDriver { func TestSPRKPlusDriver(t *testing.T) { d := initTestSPRKPlusDriver() - gobottest.Assert(t, strings.HasPrefix(d.Name(), "SPRK"), true) + assert.True(t, strings.HasPrefix(d.Name(), "SPRK")) d.SetName("NewName") - gobottest.Assert(t, d.Name(), "NewName") + assert.Equal(t, "NewName", d.Name()) } func TestSPRKPlusDriverStartAndHalt(t *testing.T) { d := initTestSPRKPlusDriver() - gobottest.Assert(t, d.Start(), nil) - gobottest.Assert(t, d.Halt(), nil) + assert.Nil(t, d.Start()) + assert.Nil(t, d.Halt()) } diff --git a/platforms/tinkerboard/adaptor_test.go b/platforms/tinkerboard/adaptor_test.go index c25ae6145..9509388e7 100644 --- a/platforms/tinkerboard/adaptor_test.go +++ b/platforms/tinkerboard/adaptor_test.go @@ -5,10 +5,10 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -74,9 +74,9 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestName(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "Tinker Board"), true) + assert.True(t, strings.HasPrefix(a.Name(), "Tinker Board")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestDigitalIO(t *testing.T) { @@ -84,14 +84,14 @@ func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) _ = a.DigitalWrite("7", 1) - gobottest.Assert(t, fs.Files[gpio17Path+"value"].Contents, "1") + assert.Equal(t, "1", fs.Files[gpio17Path+"value"].Contents) fs.Files[gpio160Path+"value"].Contents = "1" i, _ := a.DigitalRead("10") - gobottest.Assert(t, i, 1) + assert.Equal(t, 1, i) - gobottest.Assert(t, a.DigitalWrite("99", 1), fmt.Errorf("'99' is not a valid id for a digital pin")) - gobottest.Assert(t, a.Finalize(), nil) + assert.Errorf(t, a.DigitalWrite("99", 1), "'99' is not a valid id for a digital pin") + assert.Nil(t, a.Finalize()) } func TestInvalidPWMPin(t *testing.T) { @@ -99,16 +99,16 @@ func TestInvalidPWMPin(t *testing.T) { preparePwmFs(fs) err := a.PwmWrite("666", 42) - gobottest.Assert(t, err.Error(), "'666' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'666' is not a valid id for a PWM pin") err = a.ServoWrite("666", 120) - gobottest.Assert(t, err.Error(), "'666' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'666' is not a valid id for a PWM pin") err = a.PwmWrite("3", 42) - gobottest.Assert(t, err.Error(), "'3' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'3' is not a valid id for a PWM pin") err = a.ServoWrite("3", 120) - gobottest.Assert(t, err.Error(), "'3' is not a valid id for a PWM pin") + assert.Errorf(t, err, "'3' is not a valid id for a PWM pin") } func TestPwmWrite(t *testing.T) { @@ -116,24 +116,24 @@ func TestPwmWrite(t *testing.T) { preparePwmFs(fs) err := a.PwmWrite("33", 100) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmExportPath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmEnablePath].Contents, "1") - gobottest.Assert(t, fs.Files[pwmPeriodPath].Contents, fmt.Sprintf("%d", 10000000)) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "3921568") - gobottest.Assert(t, fs.Files[pwmPolarityPath].Contents, "normal") + assert.Equal(t, "0", fs.Files[pwmExportPath].Contents) + assert.Equal(t, "1", fs.Files[pwmEnablePath].Contents) + assert.Equal(t, fmt.Sprintf("%d", 10000000), fs.Files[pwmPeriodPath].Contents) + assert.Equal(t, "3921568", fs.Files[pwmDutyCyclePath].Contents) + assert.Equal(t, "normal", fs.Files[pwmPolarityPath].Contents) err = a.ServoWrite("33", 0) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "500000") + assert.Equal(t, "500000", fs.Files[pwmDutyCyclePath].Contents) err = a.ServoWrite("33", 180) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "2000000") - gobottest.Assert(t, a.Finalize(), nil) + assert.Equal(t, "2000000", fs.Files[pwmDutyCyclePath].Contents) + assert.Nil(t, a.Finalize()) } func TestSetPeriod(t *testing.T) { @@ -145,25 +145,25 @@ func TestSetPeriod(t *testing.T) { // act err := a.SetPeriod("33", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmExportPath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmEnablePath].Contents, "1") - gobottest.Assert(t, fs.Files[pwmPeriodPath].Contents, fmt.Sprintf("%d", newPeriod)) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, "0") - gobottest.Assert(t, fs.Files[pwmPolarityPath].Contents, "normal") + assert.Nil(t, err) + assert.Equal(t, "0", fs.Files[pwmExportPath].Contents) + assert.Equal(t, "1", fs.Files[pwmEnablePath].Contents) + assert.Equal(t, fmt.Sprintf("%d", newPeriod), fs.Files[pwmPeriodPath].Contents) + assert.Equal(t, "0", fs.Files[pwmDutyCyclePath].Contents) + assert.Equal(t, "normal", fs.Files[pwmPolarityPath].Contents) // arrange test for automatic adjustment of duty cycle to lower value err = a.PwmWrite("33", 127) // 127 is a little bit smaller than 50% of period - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 1270000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 1270000), fs.Files[pwmDutyCyclePath].Contents) newPeriod = newPeriod / 10 // act err = a.SetPeriod("33", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 127000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 127000), fs.Files[pwmDutyCyclePath].Contents) // arrange test for automatic adjustment of duty cycle to higher value newPeriod = newPeriod * 20 @@ -172,46 +172,46 @@ func TestSetPeriod(t *testing.T) { err = a.SetPeriod("33", newPeriod) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files[pwmDutyCyclePath].Contents, fmt.Sprintf("%d", 2540000)) + assert.Nil(t, err) + assert.Equal(t, fmt.Sprintf("%d", 2540000), fs.Files[pwmDutyCyclePath].Contents) } func TestFinalizeErrorAfterGPIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) - gobottest.Assert(t, a.DigitalWrite("7", 1), nil) + assert.Nil(t, a.DigitalWrite("7", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestFinalizeErrorAfterPWM(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(pwmMockPaths) preparePwmFs(fs) - gobottest.Assert(t, a.PwmWrite("33", 1), nil) + assert.Nil(t, a.PwmWrite("33", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestSpiDefaultValues(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.SpiDefaultBusNumber(), 0) - gobottest.Assert(t, a.SpiDefaultChipNumber(), 0) - gobottest.Assert(t, a.SpiDefaultMode(), 0) - gobottest.Assert(t, a.SpiDefaultBitCount(), 8) - gobottest.Assert(t, a.SpiDefaultMaxSpeed(), int64(500000)) + assert.Equal(t, 0, a.SpiDefaultBusNumber()) + assert.Equal(t, 0, a.SpiDefaultChipNumber()) + assert.Equal(t, 0, a.SpiDefaultMode()) + assert.Equal(t, 8, a.SpiDefaultBitCount()) + assert.Equal(t, int64(500000), a.SpiDefaultMaxSpeed()) } func TestI2cDefaultBus(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 1) + assert.Equal(t, 1, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -219,16 +219,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-4"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 4) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateSpiBusNumber(t *testing.T) { @@ -262,7 +262,7 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -303,7 +303,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -343,9 +343,9 @@ func Test_translateDigitalPin(t *testing.T) { // act chip, line, err := a.translateDigitalPin(tc.pin) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, chip, tc.wantChip) - gobottest.Assert(t, line, tc.wantLine) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantChip, chip) + assert.Equal(t, tc.wantLine, line) }) } } @@ -422,9 +422,9 @@ func Test_translatePWMPin(t *testing.T) { // act dir, channel, err := a.translatePWMPin(tc.pin) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, dir, tc.wantDir) - gobottest.Assert(t, channel, tc.wantChannel) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantDir, dir) + assert.Equal(t, tc.wantChannel, channel) }) } } diff --git a/platforms/upboard/up2/adaptor_test.go b/platforms/upboard/up2/adaptor_test.go index 8b76f9766..998df6882 100644 --- a/platforms/upboard/up2/adaptor_test.go +++ b/platforms/upboard/up2/adaptor_test.go @@ -1,16 +1,15 @@ package up2 import ( - "errors" "fmt" "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/drivers/i2c" "gobot.io/x/gobot/v2/drivers/spi" - "gobot.io/x/gobot/v2/gobottest" "gobot.io/x/gobot/v2/system" ) @@ -55,29 +54,29 @@ func initTestAdaptorWithMockedFilesystem(mockPaths []string) (*Adaptor, *system. func TestName(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, strings.HasPrefix(a.Name(), "UP2"), true) + assert.True(t, strings.HasPrefix(a.Name(), "UP2")) a.SetName("NewName") - gobottest.Assert(t, a.Name(), "NewName") + assert.Equal(t, "NewName", a.Name()) } func TestDigitalIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) _ = a.DigitalWrite("7", 1) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio462/value"].Contents, "1") + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio462/value"].Contents) fs.Files["/sys/class/gpio/gpio432/value"].Contents = "1" i, _ := a.DigitalRead("13") - gobottest.Assert(t, i, 1) + assert.Equal(t, 1, i) _ = a.DigitalWrite("green", 1) - gobottest.Assert(t, - fs.Files["/sys/class/leds/upboard:green:/brightness"].Contents, + assert.Equal(t, "1", + fs.Files["/sys/class/leds/upboard:green:/brightness"].Contents, ) - gobottest.Assert(t, a.DigitalWrite("99", 1), errors.New("'99' is not a valid id for a digital pin")) - gobottest.Assert(t, a.Finalize(), nil) + assert.Errorf(t, a.DigitalWrite("99", 1), "'99' is not a valid id for a digital pin") + assert.Nil(t, a.Finalize()) } func TestPWM(t *testing.T) { @@ -86,38 +85,38 @@ func TestPWM(t *testing.T) { fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents = "0" err := a.PwmWrite("32", 100) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/export"].Contents, "0") - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/enable"].Contents, "1") - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents, "3921568") - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents, "10000000") // pwmPeriodDefault - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/polarity"].Contents, "normal") + assert.Equal(t, "0", fs.Files["/sys/class/pwm/pwmchip0/export"].Contents) + assert.Equal(t, "1", fs.Files["/sys/class/pwm/pwmchip0/pwm0/enable"].Contents) + assert.Equal(t, "3921568", fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents) + assert.Equal(t, "10000000", fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents) // pwmPeriodDefault + assert.Equal(t, "normal", fs.Files["/sys/class/pwm/pwmchip0/pwm0/polarity"].Contents) err = a.ServoWrite("32", 0) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents, "500000") - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents, "10000000") + assert.Equal(t, "500000", fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents) + assert.Equal(t, "10000000", fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents) err = a.ServoWrite("32", 180) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents, "2000000") - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents, "10000000") + assert.Equal(t, "2000000", fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents) + assert.Equal(t, "10000000", fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents) - gobottest.Assert(t, a.Finalize(), nil) + assert.Nil(t, a.Finalize()) } func TestFinalizeErrorAfterGPIO(t *testing.T) { a, fs := initTestAdaptorWithMockedFilesystem(gpioMockPaths) - gobottest.Assert(t, a.DigitalWrite("7", 1), nil) + assert.Nil(t, a.DigitalWrite("7", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestFinalizeErrorAfterPWM(t *testing.T) { @@ -125,20 +124,20 @@ func TestFinalizeErrorAfterPWM(t *testing.T) { fs.Files["/sys/class/pwm/pwmchip0/pwm0/duty_cycle"].Contents = "0" fs.Files["/sys/class/pwm/pwmchip0/pwm0/period"].Contents = "0" - gobottest.Assert(t, a.PwmWrite("32", 1), nil) + assert.Nil(t, a.PwmWrite("32", 1)) fs.WithWriteError = true err := a.Finalize() - gobottest.Assert(t, strings.Contains(err.Error(), "write error"), true) + assert.Contains(t, err.Error(), "write error") } func TestSpiDefaultValues(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.SpiDefaultBusNumber(), 0) - gobottest.Assert(t, a.SpiDefaultMode(), 0) - gobottest.Assert(t, a.SpiDefaultMaxSpeed(), int64(500000)) + assert.Equal(t, 0, a.SpiDefaultBusNumber()) + assert.Equal(t, 0, a.SpiDefaultMode()) + assert.Equal(t, int64(500000), a.SpiDefaultMaxSpeed()) } func Test_validateSpiBusNumber(t *testing.T) { @@ -168,14 +167,14 @@ func Test_validateSpiBusNumber(t *testing.T) { // act err := a.validateSpiBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } func TestI2cDefaultBus(t *testing.T) { a := NewAdaptor() - gobottest.Assert(t, a.DefaultI2cBus(), 5) + assert.Equal(t, 5, a.DefaultI2cBus()) } func TestI2cFinalizeWithErrors(t *testing.T) { @@ -183,16 +182,16 @@ func TestI2cFinalizeWithErrors(t *testing.T) { a := NewAdaptor() a.sys.UseMockSyscall() fs := a.sys.UseMockFilesystem([]string{"/dev/i2c-5"}) - gobottest.Assert(t, a.Connect(), nil) + assert.Nil(t, a.Connect()) con, err := a.GetI2cConnection(0xff, 5) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = con.Write([]byte{0xbf}) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) fs.WithCloseError = true // act err = a.Finalize() // assert - gobottest.Assert(t, strings.Contains(err.Error(), "close error"), true) + assert.Contains(t, err.Error(), "close error") } func Test_validateI2cBusNumber(t *testing.T) { @@ -226,7 +225,7 @@ func Test_validateI2cBusNumber(t *testing.T) { // act err := a.validateI2cBusNumber(tc.busNr) // assert - gobottest.Assert(t, err, tc.wantErr) + assert.Equal(t, tc.wantErr, err) }) } } @@ -267,9 +266,9 @@ func Test_translatePWMPin(t *testing.T) { // act dir, channel, err := a.translatePWMPin(name) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, dir, tc.wantDir) - gobottest.Assert(t, channel, tc.wantChannel) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantDir, dir) + assert.Equal(t, tc.wantChannel, channel) }) } } diff --git a/robot_test.go b/robot_test.go index 7bee3324a..4d34634f6 100644 --- a/robot_test.go +++ b/robot_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestRobotConnectionEach(t *testing.T) { @@ -14,7 +14,7 @@ func TestRobotConnectionEach(t *testing.T) { r.Connections().Each(func(conn Connection) { i++ }) - gobottest.Assert(t, r.Connections().Len(), i) + assert.Equal(t, i, r.Connections().Len()) } func TestRobotToJSON(t *testing.T) { @@ -23,25 +23,25 @@ func TestRobotToJSON(t *testing.T) { return nil }) json := NewJSONRobot(r) - gobottest.Assert(t, len(json.Devices), r.Devices().Len()) - gobottest.Assert(t, len(json.Commands), len(r.Commands())) + assert.Equal(t, r.Devices().Len(), len(json.Devices)) + assert.Equal(t, len(r.Commands()), len(json.Commands)) } func TestRobotDevicesToJSON(t *testing.T) { r := newTestRobot("Robot99") json := NewJSONRobot(r) - gobottest.Assert(t, len(json.Devices), r.Devices().Len()) - gobottest.Assert(t, json.Devices[0].Name, "Device1") - gobottest.Assert(t, json.Devices[0].Driver, "*gobot.testDriver") - gobottest.Assert(t, json.Devices[0].Connection, "Connection1") - gobottest.Assert(t, len(json.Devices[0].Commands), 1) + assert.Equal(t, r.Devices().Len(), len(json.Devices)) + assert.Equal(t, "Device1", json.Devices[0].Name) + assert.Equal(t, "*gobot.testDriver", json.Devices[0].Driver) + assert.Equal(t, "Connection1", json.Devices[0].Connection) + assert.Equal(t, 1, len(json.Devices[0].Commands)) } func TestRobotStart(t *testing.T) { r := newTestRobot("Robot99") - gobottest.Assert(t, r.Start(), nil) - gobottest.Assert(t, r.Stop(), nil) - gobottest.Assert(t, r.Running(), false) + assert.Nil(t, r.Start()) + assert.Nil(t, r.Stop()) + assert.False(t, r.Running()) } func TestRobotStartAutoRun(t *testing.T) { @@ -55,13 +55,13 @@ func TestRobotStartAutoRun(t *testing.T) { ) go func() { - gobottest.Assert(t, r.Start(), nil) + assert.Nil(t, r.Start()) }() time.Sleep(10 * time.Millisecond) - gobottest.Assert(t, r.Running(), true) + assert.True(t, r.Running()) // stop it - gobottest.Assert(t, r.Stop(), nil) - gobottest.Assert(t, r.Running(), false) + assert.Nil(t, r.Stop()) + assert.False(t, r.Running()) } diff --git a/system/digitalpin_access_test.go b/system/digitalpin_access_test.go index ef822a857..58e5f4292 100644 --- a/system/digitalpin_access_test.go +++ b/system/digitalpin_access_test.go @@ -3,7 +3,7 @@ package system import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func Test_isSupportedSysfs(t *testing.T) { @@ -12,7 +12,7 @@ func Test_isSupportedSysfs(t *testing.T) { // act got := dpa.isSupported() // assert - gobottest.Assert(t, got, true) + assert.True(t, got) } func Test_isSupportedGpiod(t *testing.T) { @@ -37,7 +37,7 @@ func Test_isSupportedGpiod(t *testing.T) { // act got := dpa.isSupported() // assert - gobottest.Assert(t, got, tc.want) + assert.Equal(t, tc.want, got) }) } } @@ -48,10 +48,10 @@ func Test_createAsSysfs(t *testing.T) { // act dp := dpa.createPin("chip", 8) // assert - gobottest.Refute(t, dp, nil) + assert.NotNil(t, dp) dps := dp.(*digitalPinSysfs) // chip is dropped - gobottest.Assert(t, dps.label, "gpio8") + assert.Equal(t, "gpio8", dps.label) } func Test_createAsGpiod(t *testing.T) { @@ -65,10 +65,10 @@ func Test_createAsGpiod(t *testing.T) { // act dp := dpa.createPin(chip, 18) // assert - gobottest.Refute(t, dp, nil) + assert.NotNil(t, dp) dpg := dp.(*digitalPinGpiod) - gobottest.Assert(t, dpg.label, label) - gobottest.Assert(t, dpg.chipName, chip) + assert.Equal(t, label, dpg.label) + assert.Equal(t, chip, dpg.chipName) } func Test_createPinWithOptionsSysfs(t *testing.T) { @@ -82,7 +82,7 @@ func Test_createPinWithOptionsSysfs(t *testing.T) { dp := dpa.createPin("", 9, WithPinLabel(label)) dps := dp.(*digitalPinSysfs) // assert - gobottest.Assert(t, dps.label, label) + assert.Equal(t, label, dps.label) } func Test_createPinWithOptionsGpiod(t *testing.T) { @@ -96,7 +96,7 @@ func Test_createPinWithOptionsGpiod(t *testing.T) { dp := dpa.createPin("", 19, WithPinLabel(label)) dpg := dp.(*digitalPinGpiod) // assert - gobottest.Assert(t, dpg.label, label) + assert.Equal(t, label, dpg.label) // test fallback for empty chip - gobottest.Assert(t, dpg.chipName, "gpiochip0") + assert.Equal(t, "gpiochip0", dpg.chipName) } diff --git a/system/digitalpin_config_test.go b/system/digitalpin_config_test.go index 961543837..808286333 100644 --- a/system/digitalpin_config_test.go +++ b/system/digitalpin_config_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.DigitalPinOptioner = (*digitalPinConfig)(nil) @@ -18,10 +18,10 @@ func Test_newDigitalPinConfig(t *testing.T) { // act d := newDigitalPinConfig(label) // assert - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.label, label) - gobottest.Assert(t, d.direction, IN) - gobottest.Assert(t, d.outInitialState, 0) + assert.NotNil(t, d) + assert.Equal(t, label, d.label) + assert.Equal(t, IN, d.direction) + assert.Equal(t, 0, d.outInitialState) } func Test_newDigitalPinConfigWithOption(t *testing.T) { @@ -30,8 +30,8 @@ func Test_newDigitalPinConfigWithOption(t *testing.T) { // act d := newDigitalPinConfig("not used", WithPinLabel(label)) // assert - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.label, label) + assert.NotNil(t, d) + assert.Equal(t, label, d.label) } func TestWithPinLabel(t *testing.T) { @@ -58,8 +58,8 @@ func TestWithPinLabel(t *testing.T) { // act got := WithPinLabel(tc.setLabel)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.label, tc.setLabel) + assert.Equal(t, tc.want, got) + assert.Equal(t, tc.setLabel, dpc.label) }) } } @@ -92,9 +92,9 @@ func TestWithPinDirectionOutput(t *testing.T) { // act got := WithPinDirectionOutput(newVal)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.direction, "out") - gobottest.Assert(t, dpc.outInitialState, tc.wantVal) + assert.Equal(t, tc.want, got) + assert.Equal(t, "out", dpc.direction) + assert.Equal(t, tc.wantVal, dpc.outInitialState) }) } } @@ -120,9 +120,9 @@ func TestWithPinDirectionInput(t *testing.T) { // act got := WithPinDirectionInput()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.direction, "in") - gobottest.Assert(t, dpc.outInitialState, initValOut) + assert.Equal(t, tc.want, got) + assert.Equal(t, "in", dpc.direction) + assert.Equal(t, initValOut, dpc.outInitialState) }) } } @@ -147,8 +147,8 @@ func TestWithPinActiveLow(t *testing.T) { // act got := WithPinActiveLow()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.activeLow, true) + assert.Equal(t, tc.want, got) + assert.True(t, dpc.activeLow) }) } } @@ -174,8 +174,8 @@ func TestWithPinPullDown(t *testing.T) { // act got := WithPinPullDown()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.bias, digitalPinBiasPullDown) + assert.Equal(t, tc.want, got) + assert.Equal(t, digitalPinBiasPullDown, dpc.bias) }) } } @@ -201,8 +201,8 @@ func TestWithPinPullUp(t *testing.T) { // act got := WithPinPullUp()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.bias, digitalPinBiasPullUp) + assert.Equal(t, tc.want, got) + assert.Equal(t, digitalPinBiasPullUp, dpc.bias) }) } } @@ -232,8 +232,8 @@ func TestWithPinOpenDrain(t *testing.T) { // act got := WithPinOpenDrain()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.drive, digitalPinDriveOpenDrain) + assert.Equal(t, tc.want, got) + assert.Equal(t, digitalPinDriveOpenDrain, dpc.drive) }) } } @@ -263,8 +263,8 @@ func TestWithPinOpenSource(t *testing.T) { // act got := WithPinOpenSource()(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.drive, digitalPinDriveOpenSource) + assert.Equal(t, tc.want, got) + assert.Equal(t, digitalPinDriveOpenSource, dpc.drive) }) } } @@ -294,8 +294,8 @@ func TestWithPinDebounce(t *testing.T) { // act got := WithPinDebounce(newVal)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.debouncePeriod, newVal) + assert.Equal(t, tc.want, got) + assert.Equal(t, newVal, dpc.debouncePeriod) }) } } @@ -312,6 +312,7 @@ func TestWithPinEventOnFallingEdge(t *testing.T) { }{ "no_change": { oldEdge: newVal, + want: false, }, "change": { oldEdge: oldVal, @@ -326,9 +327,13 @@ func TestWithPinEventOnFallingEdge(t *testing.T) { // act got := WithPinEventOnFallingEdge(handler)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.edge, newVal) - gobottest.Refute(t, dpc.edgeEventHandler, nil) + assert.Equal(t, tc.want, got) + assert.Equal(t, newVal, dpc.edge) + if tc.want { + assert.NotNil(t, dpc.edgeEventHandler) + } else { + assert.Nil(t, dpc.edgeEventHandler) + } }) } } @@ -345,6 +350,7 @@ func TestWithPinEventOnRisingEdge(t *testing.T) { }{ "no_change": { oldEdge: newVal, + want: false, }, "change": { oldEdge: oldVal, @@ -359,9 +365,13 @@ func TestWithPinEventOnRisingEdge(t *testing.T) { // act got := WithPinEventOnRisingEdge(handler)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.edge, newVal) - gobottest.Refute(t, dpc.edgeEventHandler, nil) + assert.Equal(t, tc.want, got) + assert.Equal(t, newVal, dpc.edge) + if tc.want { + assert.NotNil(t, dpc.edgeEventHandler) + } else { + assert.Nil(t, dpc.edgeEventHandler) + } }) } } @@ -378,6 +388,7 @@ func TestWithPinEventOnBothEdges(t *testing.T) { }{ "no_change": { oldEdge: newVal, + want: false, }, "change": { oldEdge: oldVal, @@ -392,9 +403,13 @@ func TestWithPinEventOnBothEdges(t *testing.T) { // act got := WithPinEventOnBothEdges(handler)(dpc) // assert - gobottest.Assert(t, got, tc.want) - gobottest.Assert(t, dpc.edge, newVal) - gobottest.Refute(t, dpc.edgeEventHandler, nil) + assert.Equal(t, tc.want, got) + assert.Equal(t, newVal, dpc.edge) + if tc.want { + assert.NotNil(t, dpc.edgeEventHandler) + } else { + assert.Nil(t, dpc.edgeEventHandler) + } }) } } diff --git a/system/digitalpin_gpiod_test.go b/system/digitalpin_gpiod_test.go index 6ed077469..78e69f78a 100644 --- a/system/digitalpin_gpiod_test.go +++ b/system/digitalpin_gpiod_test.go @@ -2,11 +2,10 @@ package system import ( "fmt" - "strings" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.DigitalPinner = (*digitalPinGpiod)(nil) @@ -24,12 +23,12 @@ func Test_newDigitalPinGpiod(t *testing.T) { // act d := newDigitalPinGpiod(chip, pin) // assert - gobottest.Refute(t, d, nil) - gobottest.Assert(t, d.chipName, chip) - gobottest.Assert(t, d.pin, pin) - gobottest.Assert(t, d.label, label) - gobottest.Assert(t, d.direction, IN) - gobottest.Assert(t, d.outInitialState, 0) + assert.NotNil(t, d) + assert.Equal(t, chip, d.chipName) + assert.Equal(t, pin, d.pin) + assert.Equal(t, label, d.label) + assert.Equal(t, IN, d.direction) + assert.Equal(t, 0, d.outInitialState) } func Test_newDigitalPinGpiodWithOptions(t *testing.T) { @@ -41,7 +40,7 @@ func Test_newDigitalPinGpiodWithOptions(t *testing.T) { // act dp := newDigitalPinGpiod("", 9, WithPinLabel(label)) // assert - gobottest.Assert(t, dp.label, label) + assert.Equal(t, label, dp.label) } func TestApplyOptions(t *testing.T) { @@ -102,12 +101,12 @@ func TestApplyOptions(t *testing.T) { // act err := d.ApplyOptions(optionFunction1, optionFunction2) // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, d.digitalPinConfig.direction, "test") - gobottest.Assert(t, d.digitalPinConfig.drive, 15) - gobottest.Assert(t, reconfigured, tc.wantReconfigured) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, "test", d.digitalPinConfig.direction) + assert.Equal(t, 15, d.digitalPinConfig.drive) + assert.Equal(t, tc.wantReconfigured, reconfigured) if reconfigured > 0 { - gobottest.Assert(t, inputForced, false) + assert.False(t, inputForced) } }) } @@ -147,9 +146,9 @@ func TestExport(t *testing.T) { // act err := d.Export() // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, inputForced, false) - gobottest.Assert(t, reconfigured, tc.wantReconfigured) + assert.Equal(t, tc.wantErr, err) + assert.False(t, inputForced) + assert.Equal(t, tc.wantReconfigured, reconfigured) }) } } @@ -207,10 +206,10 @@ func TestUnexport(t *testing.T) { // act err := dp.Unexport() // assert - gobottest.Assert(t, err, tc.wantErr) - gobottest.Assert(t, reconfigured, tc.wantReconfigured) + assert.Equal(t, tc.wantErr, err) + assert.Equal(t, tc.wantReconfigured, reconfigured) if reconfigured > 0 { - gobottest.Assert(t, inputForced, true) + assert.True(t, inputForced) } }) } @@ -255,12 +254,12 @@ func TestWrite(t *testing.T) { // assert if tc.wantErr != nil { for _, want := range tc.wantErr { - gobottest.Assert(t, strings.Contains(err.Error(), want), true) + assert.Contains(t, err.Error(), want) } } else { - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } - gobottest.Assert(t, lm.lastVal, tc.want) + assert.Equal(t, tc.want, lm.lastVal) }) } } @@ -290,12 +289,12 @@ func TestRead(t *testing.T) { // assert if tc.wantErr != nil { for _, want := range tc.wantErr { - gobottest.Assert(t, strings.Contains(err.Error(), want), true) + assert.Contains(t, err.Error(), want) } } else { - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } - gobottest.Assert(t, tc.simVal, got) + assert.Equal(t, got, tc.simVal) }) } } diff --git a/system/digitalpin_sysfs_test.go b/system/digitalpin_sysfs_test.go index 992a06be5..5c2fe57b0 100644 --- a/system/digitalpin_sysfs_test.go +++ b/system/digitalpin_sysfs_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.DigitalPinner = (*digitalPinSysfs)(nil) @@ -29,51 +29,51 @@ func TestDigitalPin(t *testing.T) { } pin, fs := initTestDigitalPinSysFsWithMockedFilesystem(mockPaths) - gobottest.Assert(t, pin.pin, "10") - gobottest.Assert(t, pin.label, "gpio10") - gobottest.Assert(t, pin.valFile, nil) + assert.Equal(t, "10", pin.pin) + assert.Equal(t, "gpio10", pin.label) + assert.Nil(t, pin.valFile) err := pin.Unexport() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/unexport"].Contents, "10") + assert.Nil(t, err) + assert.Equal(t, "10", fs.Files["/sys/class/gpio/unexport"].Contents) err = pin.Export() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/export"].Contents, "10") - gobottest.Refute(t, pin.valFile, nil) + assert.Nil(t, err) + assert.Equal(t, "10", fs.Files["/sys/class/gpio/export"].Contents) + assert.NotNil(t, pin.valFile) err = pin.Write(1) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio10/value"].Contents, "1") + assert.Nil(t, err) + assert.Equal(t, "1", fs.Files["/sys/class/gpio/gpio10/value"].Contents) err = pin.ApplyOptions(WithPinDirectionInput()) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio10/direction"].Contents, "in") + assert.Nil(t, err) + assert.Equal(t, "in", fs.Files["/sys/class/gpio/gpio10/direction"].Contents) data, _ := pin.Read() - gobottest.Assert(t, 1, data) + assert.Equal(t, data, 1) pin2 := newDigitalPinSysfs(fs, "30") err = pin2.Write(1) - gobottest.Assert(t, err.Error(), "pin has not been exported") + assert.Errorf(t, err, "pin has not been exported") data, err = pin2.Read() - gobottest.Assert(t, err.Error(), "pin has not been exported") - gobottest.Assert(t, data, 0) + assert.Errorf(t, err, "pin has not been exported") + assert.Equal(t, 0, data) writeFile = func(File, []byte) (int, error) { return 0, &os.PathError{Err: Syscall_EINVAL} } err = pin.Unexport() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) writeFile = func(File, []byte) (int, error) { return 0, &os.PathError{Err: errors.New("write error")} } err = pin.Unexport() - gobottest.Assert(t, err.(*os.PathError).Err, errors.New("write error")) + assert.Errorf(t, err.(*os.PathError).Err, "write error") // assert a busy error is dropped (just means "already exported") cnt := 0 @@ -85,14 +85,14 @@ func TestDigitalPin(t *testing.T) { return 0, nil } err = pin.Export() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) // assert write error on export writeFile = func(File, []byte) (int, error) { return 0, &os.PathError{Err: errors.New("write error")} } err = pin.Export() - gobottest.Assert(t, err.(*os.PathError).Err, errors.New("write error")) + assert.Errorf(t, err.(*os.PathError).Err, "write error") } func TestDigitalPinExportError(t *testing.T) { @@ -107,7 +107,7 @@ func TestDigitalPinExportError(t *testing.T) { } err := pin.Export() - gobottest.Assert(t, err.Error(), " : /sys/class/gpio/gpio10/direction: no such file") + assert.Errorf(t, err, " : /sys/class/gpio/gpio10/direction: no such file") } func TestDigitalPinUnexportError(t *testing.T) { @@ -121,5 +121,5 @@ func TestDigitalPinUnexportError(t *testing.T) { } err := pin.Unexport() - gobottest.Assert(t, err.Error(), " : device or resource busy") + assert.Errorf(t, err, " : device or resource busy") } diff --git a/system/fs_mock_test.go b/system/fs_mock_test.go index 78b974ad6..40202c980 100644 --- a/system/fs_mock_test.go +++ b/system/fs_mock_test.go @@ -4,42 +4,42 @@ import ( "sort" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestMockFilesystemOpen(t *testing.T) { fs := newMockFilesystem([]string{"foo"}) f1 := fs.Files["foo"] - gobottest.Assert(t, f1.Opened, false) + assert.False(t, f1.Opened) f2, err := fs.openFile("foo", 0, 0666) - gobottest.Assert(t, f1, f2) - gobottest.Assert(t, err, nil) + assert.Equal(t, f2, f1) + assert.Nil(t, err) err = f2.Sync() - gobottest.Assert(t, err, nil) + assert.Nil(t, err) _, err = fs.openFile("bar", 0, 0666) - gobottest.Assert(t, err.Error(), " : bar: no such file") + assert.Errorf(t, err, " : bar: no such file") fs.Add("bar") f4, _ := fs.openFile("bar", 0, 0666) - gobottest.Refute(t, f4.Fd(), f1.Fd()) + assert.NotEqual(t, f1.Fd(), f4.Fd()) } func TestMockFilesystemStat(t *testing.T) { fs := newMockFilesystem([]string{"foo", "bar/baz"}) fileStat, err := fs.stat("foo") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fileStat.IsDir(), false) + assert.Nil(t, err) + assert.False(t, fileStat.IsDir()) dirStat, err := fs.stat("bar") - gobottest.Assert(t, err, nil) - gobottest.Assert(t, dirStat.IsDir(), true) + assert.Nil(t, err) + assert.True(t, dirStat.IsDir()) _, err = fs.stat("plonk") - gobottest.Assert(t, err.Error(), " : plonk: no such file") + assert.Errorf(t, err, " : plonk: no such file") } func TestMockFilesystemFind(t *testing.T) { @@ -61,9 +61,9 @@ func TestMockFilesystemFind(t *testing.T) { // act dirs, err := fs.find(tt.baseDir, tt.pattern) // assert - gobottest.Assert(t, err, nil) + assert.Nil(t, err) sort.Strings(dirs) - gobottest.Assert(t, dirs, tt.want) + assert.Equal(t, tt.want, dirs) }) } } @@ -73,14 +73,14 @@ func TestMockFilesystemWrite(t *testing.T) { f1 := fs.Files["bar"] f2, err := fs.openFile("bar", 0, 0666) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) // Never been read or written. - gobottest.Assert(t, f1.Seq <= 0, true) + assert.True(t, f1.Seq <= 0) _, _ = f2.WriteString("testing") // Was written. - gobottest.Assert(t, f1.Seq > 0, true) - gobottest.Assert(t, f1.Contents, "testing") + assert.True(t, f1.Seq > 0) + assert.Equal(t, "testing", f1.Contents) } func TestMockFilesystemRead(t *testing.T) { @@ -89,18 +89,18 @@ func TestMockFilesystemRead(t *testing.T) { f1.Contents = "Yip" f2, err := fs.openFile("bar", 0, 0666) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) // Never been read or written. - gobottest.Assert(t, f1.Seq <= 0, true) + assert.True(t, f1.Seq <= 0) buffer := make([]byte, 20) n, _ := f2.Read(buffer) // Was read. - gobottest.Assert(t, f1.Seq > 0, true) - gobottest.Assert(t, n, 3) - gobottest.Assert(t, string(buffer[:3]), "Yip") + assert.True(t, f1.Seq > 0) + assert.Equal(t, 3, n) + assert.Equal(t, "Yip", string(buffer[:3])) n, _ = f2.ReadAt(buffer, 10) - gobottest.Assert(t, n, 3) + assert.Equal(t, 3, n) } diff --git a/system/fs_test.go b/system/fs_test.go index ebcbfd8bf..0f5e4e8ad 100644 --- a/system/fs_test.go +++ b/system/fs_test.go @@ -4,19 +4,19 @@ import ( "os" "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestFilesystemOpen(t *testing.T) { fs := &nativeFilesystem{} file, err := fs.openFile(os.DevNull, os.O_RDONLY, 0666) - gobottest.Assert(t, err, nil) + assert.Nil(t, err) var _ File = file } func TestFilesystemStat(t *testing.T) { fs := &nativeFilesystem{} fileInfo, err := fs.stat(os.DevNull) - gobottest.Assert(t, err, nil) - gobottest.Refute(t, fileInfo, nil) + assert.Nil(t, err) + assert.NotNil(t, fileInfo) } diff --git a/system/i2c_device_test.go b/system/i2c_device_test.go index f40124d03..1e5e666a1 100644 --- a/system/i2c_device_test.go +++ b/system/i2c_device_test.go @@ -1,13 +1,12 @@ package system import ( - "errors" "os" "testing" "unsafe" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) const dev = "/dev/i2c-1" @@ -80,11 +79,11 @@ func TestNewI2cDevice(t *testing.T) { d, err := a.NewI2cDevice(tc.dev) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) - gobottest.Assert(t, d, (*i2cDevice)(nil)) + assert.Errorf(t, err, tc.wantErr) + assert.Equal(t, (*i2cDevice)(nil), d) } else { var _ gobot.I2cSystemDevicer = d - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } }) } @@ -94,7 +93,7 @@ func TestClose(t *testing.T) { // arrange d, _ := initTestI2cDeviceWithMockedSys() // act & assert - gobottest.Assert(t, d.Close(), nil) + assert.Nil(t, d.Close()) } func TestWriteRead(t *testing.T) { @@ -106,11 +105,11 @@ func TestWriteRead(t *testing.T) { wn, werr := d.Write(1, wbuf) rn, rerr := d.Read(1, rbuf) // assert - gobottest.Assert(t, werr, nil) - gobottest.Assert(t, rerr, nil) - gobottest.Assert(t, wn, len(wbuf)) - gobottest.Assert(t, rn, len(wbuf)) // will read only the written values - gobottest.Assert(t, wbuf, rbuf[:len(wbuf)]) + assert.Nil(t, werr) + assert.Nil(t, rerr) + assert.Equal(t, len(wbuf), wn) + assert.Equal(t, len(wbuf), rn) // will read only the written values + assert.Equal(t, rbuf[:len(wbuf)], wbuf) } func TestReadByte(t *testing.T) { @@ -143,15 +142,15 @@ func TestReadByte(t *testing.T) { got, err := d.ReadByte(2) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, want) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_READ)) - gobottest.Assert(t, msc.smbus.command, byte(0)) // register is set to 0 in that case - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_BYTE)) + assert.Nil(t, err) + assert.Equal(t, want, got) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_READ), msc.smbus.readWrite) + assert.Equal(t, byte(0), msc.smbus.command) // register is set to 0 in that case + assert.Equal(t, uint32(I2C_SMBUS_BYTE), msc.smbus.protocol) } }) } @@ -190,15 +189,15 @@ func TestReadByteData(t *testing.T) { got, err := d.ReadByteData(3, reg) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, want) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_READ)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_BYTE_DATA)) + assert.Nil(t, err) + assert.Equal(t, want, got) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_READ), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_BYTE_DATA), msc.smbus.protocol) } }) } @@ -240,15 +239,15 @@ func TestReadWordData(t *testing.T) { got, err := d.ReadWordData(4, reg) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, got, want) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_READ)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_WORD_DATA)) + assert.Nil(t, err) + assert.Equal(t, want, got) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_READ), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_WORD_DATA), msc.smbus.protocol) } }) } @@ -298,16 +297,16 @@ func TestReadBlockData(t *testing.T) { err := d.ReadBlockData(5, reg, buf) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, buf, msc.dataSlice) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.sliceSize, uint8(len(buf)+1)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_READ)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_I2C_BLOCK_DATA)) + assert.Nil(t, err) + assert.Equal(t, msc.dataSlice, buf) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, uint8(len(buf)+1), msc.sliceSize) + assert.Equal(t, byte(I2C_SMBUS_READ), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_I2C_BLOCK_DATA), msc.smbus.protocol) } }) } @@ -342,14 +341,14 @@ func TestWriteByte(t *testing.T) { err := d.WriteByte(6, val) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_WRITE)) - gobottest.Assert(t, msc.smbus.command, val) // in byte write, the register/command is used for the value - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_BYTE)) + assert.Nil(t, err) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_WRITE), msc.smbus.readWrite) + assert.Equal(t, val, msc.smbus.command) // in byte write, the register/command is used for the value + assert.Equal(t, uint32(I2C_SMBUS_BYTE), msc.smbus.protocol) } }) } @@ -387,16 +386,16 @@ func TestWriteByteData(t *testing.T) { err := d.WriteByteData(7, reg, val) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_WRITE)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_BYTE_DATA)) - gobottest.Assert(t, len(msc.dataSlice), 1) - gobottest.Assert(t, msc.dataSlice[0], val) + assert.Nil(t, err) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_WRITE), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_BYTE_DATA), msc.smbus.protocol) + assert.Equal(t, 1, len(msc.dataSlice)) + assert.Equal(t, val, msc.dataSlice[0]) } }) } @@ -436,18 +435,18 @@ func TestWriteWordData(t *testing.T) { err := d.WriteWordData(8, reg, val) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_WRITE)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_WORD_DATA)) - gobottest.Assert(t, len(msc.dataSlice), 2) + assert.Nil(t, err) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, byte(I2C_SMBUS_WRITE), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_WORD_DATA), msc.smbus.protocol) + assert.Equal(t, 2, len(msc.dataSlice)) // all common drivers write LSByte first - gobottest.Assert(t, msc.dataSlice[0], wantLSByte) - gobottest.Assert(t, msc.dataSlice[1], wantMSByte) + assert.Equal(t, wantLSByte, msc.dataSlice[0]) + assert.Equal(t, wantMSByte, msc.dataSlice[1]) } }) } @@ -493,17 +492,17 @@ func TestWriteBlockData(t *testing.T) { err := d.WriteBlockData(9, reg, data) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) - gobottest.Assert(t, msc.lastFile, d.file) - gobottest.Assert(t, msc.lastSignal, uintptr(I2C_SMBUS)) - gobottest.Assert(t, msc.sliceSize, uint8(len(data)+1)) // including size element - gobottest.Assert(t, msc.smbus.readWrite, byte(I2C_SMBUS_WRITE)) - gobottest.Assert(t, msc.smbus.command, reg) - gobottest.Assert(t, msc.smbus.protocol, uint32(I2C_SMBUS_I2C_BLOCK_DATA)) - gobottest.Assert(t, msc.dataSlice[0], uint8(len(data))) // data size - gobottest.Assert(t, msc.dataSlice[1:], data) + assert.Nil(t, err) + assert.Equal(t, d.file, msc.lastFile) + assert.Equal(t, uintptr(I2C_SMBUS), msc.lastSignal) + assert.Equal(t, uint8(len(data)+1), msc.sliceSize) // including size element + assert.Equal(t, byte(I2C_SMBUS_WRITE), msc.smbus.readWrite) + assert.Equal(t, reg, msc.smbus.command) + assert.Equal(t, uint32(I2C_SMBUS_I2C_BLOCK_DATA), msc.smbus.protocol) + assert.Equal(t, uint8(len(data)), msc.dataSlice[0]) // data size + assert.Equal(t, data, msc.dataSlice[1:]) } }) } @@ -515,7 +514,7 @@ func TestWriteBlockDataTooMuch(t *testing.T) { // act err := d.WriteBlockData(10, 0x01, make([]byte, 33)) // assert - gobottest.Assert(t, err, errors.New("Writing blocks larger than 32 bytes (33) not supported")) + assert.Errorf(t, err, "Writing blocks larger than 32 bytes (33) not supported") } func Test_setAddress(t *testing.T) { @@ -524,8 +523,8 @@ func Test_setAddress(t *testing.T) { // act err := d.setAddress(0xff) // assert - gobottest.Assert(t, err, nil) - gobottest.Assert(t, msc.devAddress, uintptr(0xff)) + assert.Nil(t, err) + assert.Equal(t, uintptr(0xff), msc.devAddress) } func Test_queryFunctionality(t *testing.T) { @@ -566,16 +565,16 @@ func Test_queryFunctionality(t *testing.T) { err := d.queryFunctionality(tc.requested, "test"+name) // assert if tc.wantErr != "" { - gobottest.Assert(t, err.Error(), tc.wantErr) + assert.Errorf(t, err, tc.wantErr) } else { - gobottest.Assert(t, err, nil) + assert.Nil(t, err) } if tc.wantFile { - gobottest.Refute(t, d.file, nil) + assert.NotNil(t, d.file) } else { - gobottest.Assert(t, d.file, (*MockFile)(nil)) + assert.Equal(t, (*MockFile)(nil), d.file) } - gobottest.Assert(t, d.funcs, tc.wantFuncs) + assert.Equal(t, tc.wantFuncs, d.funcs) }) } } diff --git a/system/pwmpin_sysfs_test.go b/system/pwmpin_sysfs_test.go index 44c224973..ba3a84c48 100644 --- a/system/pwmpin_sysfs_test.go +++ b/system/pwmpin_sysfs_test.go @@ -4,8 +4,8 @@ import ( "os" "testing" + "github.com/stretchr/testify/assert" "gobot.io/x/gobot/v2" - "gobot.io/x/gobot/v2/gobottest" ) var _ gobot.PWMPinner = (*pwmPinSysFs)(nil) @@ -32,45 +32,45 @@ func TestPwmPin(t *testing.T) { } pin, fs := initTestPWMPinSysFsWithMockedFilesystem(mockedPaths) - gobottest.Assert(t, pin.pin, "10") + assert.Equal(t, "10", pin.pin) err := pin.Unexport() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/unexport"].Contents, "10") + assert.Nil(t, err) + assert.Equal(t, "10", fs.Files["/sys/class/pwm/pwmchip0/unexport"].Contents) err = pin.Export() - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/export"].Contents, "10") + assert.Nil(t, err) + assert.Equal(t, "10", fs.Files["/sys/class/pwm/pwmchip0/export"].Contents) - gobottest.Assert(t, pin.SetPolarity(false), nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, inverted) + assert.Nil(t, pin.SetPolarity(false)) + assert.Equal(t, inverted, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents) pol, _ := pin.Polarity() - gobottest.Assert(t, pol, false) - gobottest.Assert(t, pin.SetPolarity(true), nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, normal) + assert.False(t, pol) + assert.Nil(t, pin.SetPolarity(true)) + assert.Equal(t, normal, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents) pol, _ = pin.Polarity() - gobottest.Assert(t, pol, true) + assert.True(t, pol) - gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/enable"].Contents, "1") + assert.NotEqual(t, "1", fs.Files["/sys/class/pwm/pwmchip0/pwm10/enable"].Contents) err = pin.SetEnabled(true) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/enable"].Contents, "1") + assert.Nil(t, err) + assert.Equal(t, "1", fs.Files["/sys/class/pwm/pwmchip0/pwm10/enable"].Contents) err = pin.SetPolarity(true) - gobottest.Assert(t, err.Error(), "Cannot set PWM polarity when enabled") + assert.Errorf(t, err, "Cannot set PWM polarity when enabled") fs.Files["/sys/class/pwm/pwmchip0/pwm10/period"].Contents = "6" data, _ := pin.Period() - gobottest.Assert(t, data, uint32(6)) - gobottest.Assert(t, pin.SetPeriod(100000), nil) + assert.Equal(t, uint32(6), data) + assert.Nil(t, pin.SetPeriod(100000)) data, _ = pin.Period() - gobottest.Assert(t, data, uint32(100000)) + assert.Equal(t, uint32(100000), data) - gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "1") + assert.NotEqual(t, "1", fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents) err = pin.SetDutyCycle(100) - gobottest.Assert(t, err, nil) - gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "100") + assert.Nil(t, err) + assert.Equal(t, "100", fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents) data, _ = pin.DutyCycle() - gobottest.Assert(t, data, uint32(100)) + assert.Equal(t, uint32(100), data) } func TestPwmPinAlreadyExported(t *testing.T) { @@ -88,7 +88,7 @@ func TestPwmPinAlreadyExported(t *testing.T) { } // no error indicates that the pin was already exported - gobottest.Assert(t, pin.Export(), nil) + assert.Nil(t, pin.Export()) } func TestPwmPinExportError(t *testing.T) { @@ -107,7 +107,7 @@ func TestPwmPinExportError(t *testing.T) { // no error indicates that the pin was already exported err := pin.Export() - gobottest.Assert(t, err.Error(), "Export() failed for id 10 with : bad address") + assert.Errorf(t, err, "Export() failed for id 10 with : bad address") } func TestPwmPinUnxportError(t *testing.T) { @@ -125,7 +125,7 @@ func TestPwmPinUnxportError(t *testing.T) { } err := pin.Unexport() - gobottest.Assert(t, err.Error(), "Unexport() failed for id 10 with : device or resource busy") + assert.Errorf(t, err, "Unexport() failed for id 10 with : device or resource busy") } func TestPwmPinPeriodError(t *testing.T) { @@ -143,7 +143,7 @@ func TestPwmPinPeriodError(t *testing.T) { } _, err := pin.Period() - gobottest.Assert(t, err.Error(), "Period() failed for id 10 with : device or resource busy") + assert.Errorf(t, err, "Period() failed for id 10 with : device or resource busy") } func TestPwmPinPolarityError(t *testing.T) { @@ -161,7 +161,7 @@ func TestPwmPinPolarityError(t *testing.T) { } _, err := pin.Polarity() - gobottest.Assert(t, err.Error(), "Polarity() failed for id 10 with : device or resource busy") + assert.Errorf(t, err, "Polarity() failed for id 10 with : device or resource busy") } func TestPwmPinDutyCycleError(t *testing.T) { @@ -179,5 +179,5 @@ func TestPwmPinDutyCycleError(t *testing.T) { } _, err := pin.DutyCycle() - gobottest.Assert(t, err.Error(), "DutyCycle() failed for id 10 with : device or resource busy") + assert.Errorf(t, err, "DutyCycle() failed for id 10 with : device or resource busy") } diff --git a/system/spi_access_test.go b/system/spi_access_test.go index 6f087ae4c..d70be2656 100644 --- a/system/spi_access_test.go +++ b/system/spi_access_test.go @@ -3,7 +3,7 @@ package system import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestGpioSpi_isSupported(t *testing.T) { @@ -12,7 +12,7 @@ func TestGpioSpi_isSupported(t *testing.T) { // act got := gsa.isSupported() // assert - gobottest.Assert(t, got, true) + assert.True(t, got) } func TestPeriphioSpi_isSupported(t *testing.T) { @@ -37,7 +37,7 @@ func TestPeriphioSpi_isSupported(t *testing.T) { // act got := psa.isSupported() // assert - gobottest.Assert(t, got, tc.want) + assert.Equal(t, tc.want, got) }) } } diff --git a/system/system_test.go b/system/system_test.go index 54eb87486..9f2c7243a 100644 --- a/system/system_test.go +++ b/system/system_test.go @@ -3,7 +3,7 @@ package system import ( "testing" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestNewAccesser(t *testing.T) { @@ -13,10 +13,10 @@ func TestNewAccesser(t *testing.T) { nativeSys := a.sys.(*nativeSyscall) nativeFsSys := a.fs.(*nativeFilesystem) perphioSpi := a.spiAccess.(*periphioSpiAccess) - gobottest.Refute(t, a, nil) - gobottest.Refute(t, nativeSys, nil) - gobottest.Refute(t, nativeFsSys, nil) - gobottest.Refute(t, perphioSpi, nil) + assert.NotNil(t, a) + assert.NotNil(t, nativeSys) + assert.NotNil(t, nativeFsSys) + assert.NotNil(t, perphioSpi) } func TestNewAccesser_NewSpiDevice(t *testing.T) { @@ -34,13 +34,13 @@ func TestNewAccesser_NewSpiDevice(t *testing.T) { // act con, err := a.NewSpiDevice(busNum, chipNum, mode, bits, maxSpeed) // assert - gobottest.Assert(t, err, nil) - gobottest.Refute(t, con, nil) - gobottest.Assert(t, spi.busNum, busNum) - gobottest.Assert(t, spi.chipNum, chipNum) - gobottest.Assert(t, spi.mode, mode) - gobottest.Assert(t, spi.bits, bits) - gobottest.Assert(t, spi.maxSpeed, maxSpeed) + assert.Nil(t, err) + assert.NotNil(t, con) + assert.Equal(t, busNum, spi.busNum) + assert.Equal(t, chipNum, spi.chipNum) + assert.Equal(t, mode, spi.mode) + assert.Equal(t, bits, spi.bits) + assert.Equal(t, maxSpeed, spi.maxSpeed) } func TestNewAccesser_IsSysfsDigitalPinAccess(t *testing.T) { @@ -75,17 +75,17 @@ func TestNewAccesser_IsSysfsDigitalPinAccess(t *testing.T) { // act got := a.IsSysfsDigitalPinAccess() // assert - gobottest.Refute(t, a, nil) + assert.NotNil(t, a) if tc.wantSys { - gobottest.Assert(t, got, true) + assert.True(t, got) dpaSys := a.digitalPinAccess.(*sysfsDigitalPinAccess) - gobottest.Refute(t, dpaSys, nil) - gobottest.Assert(t, dpaSys.fs, a.fs.(*nativeFilesystem)) + assert.NotNil(t, dpaSys) + assert.Equal(t, a.fs.(*nativeFilesystem), dpaSys.fs) } else { - gobottest.Assert(t, got, false) + assert.False(t, got) dpaGpiod := a.digitalPinAccess.(*gpiodDigitalPinAccess) - gobottest.Refute(t, dpaGpiod, nil) - gobottest.Assert(t, dpaGpiod.fs, a.fs.(*nativeFilesystem)) + assert.NotNil(t, dpaGpiod) + assert.Equal(t, a.fs.(*nativeFilesystem), dpaGpiod.fs) } }) } diff --git a/utils_test.go b/utils_test.go index 383baa578..e07e299e6 100644 --- a/utils_test.go +++ b/utils_test.go @@ -1,11 +1,10 @@ package gobot import ( - "strings" "testing" "time" - "gobot.io/x/gobot/v2/gobottest" + "github.com/stretchr/testify/assert" ) func TestEvery(t *testing.T) { @@ -61,22 +60,22 @@ func TestAfter(t *testing.T) { t.Errorf("After was not called") } - gobottest.Assert(t, i, 1) + assert.Equal(t, 1, i) } func TestFromScale(t *testing.T) { - gobottest.Assert(t, FromScale(5, 0, 10), 0.5) + assert.Equal(t, 0.5, FromScale(5, 0, 10)) } func TestToScale(t *testing.T) { - gobottest.Assert(t, ToScale(500, 0, 10), 10.0) - gobottest.Assert(t, ToScale(-1, 0, 10), 0.0) - gobottest.Assert(t, ToScale(0.5, 0, 10), 5.0) + assert.Equal(t, 10.0, ToScale(500, 0, 10)) + assert.Equal(t, 0.0, ToScale(-1, 0, 10)) + assert.Equal(t, 5.0, ToScale(0.5, 0, 10)) } func TestRescale(t *testing.T) { - gobottest.Assert(t, Rescale(500, 0, 1000, 0, 10), 5.0) - gobottest.Assert(t, Rescale(-1.0, -1, 0, 490, 350), 490.0) + assert.Equal(t, 5.0, Rescale(500, 0, 1000, 0, 10)) + assert.Equal(t, 490.0, Rescale(-1.0, -1, 0, 490, 350)) } func TestRand(t *testing.T) { @@ -89,5 +88,5 @@ func TestRand(t *testing.T) { func TestDefaultName(t *testing.T) { name := DefaultName("tester") - gobottest.Assert(t, strings.Contains(name, "tester"), true) + assert.Contains(t, name, "tester") }