diff --git a/config_test.go b/config_test.go index fbd200dc..39e7deec 100644 --- a/config_test.go +++ b/config_test.go @@ -6,9 +6,9 @@ import ( "os" "testing" - . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/config" "github.com/aerokube/selenoid/session" + assert "github.com/stretchr/testify/require" ) const testLogConf = "config/container-logs.json" @@ -34,15 +34,16 @@ func TestConfig(t *testing.T) { defer os.Remove(confFile) conf := config.NewConfig() err := conf.Load(confFile, testLogConf) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) } func TestConfigError(t *testing.T) { confFile := configfile(`{}`) - os.Remove(confFile) + _ = os.Remove(confFile) conf := config.NewConfig() err := conf.Load(confFile, testLogConf) - AssertThat(t, err.Error(), EqualTo{fmt.Sprintf("browsers config: read error: open %s: no such file or directory", confFile)}) + assert.Error(t, err) + assert.Equal(t, err.Error(), fmt.Sprintf("browsers config: read error: open %s: no such file or directory", confFile)) } func TestLogConfigError(t *testing.T) { @@ -50,7 +51,7 @@ func TestLogConfigError(t *testing.T) { defer os.Remove(confFile) conf := config.NewConfig() err := conf.Load(confFile, "some-missing-file") - AssertThat(t, err, Not{nil}) + assert.Error(t, err) } func TestConfigParseError(t *testing.T) { @@ -58,7 +59,8 @@ func TestConfigParseError(t *testing.T) { defer os.Remove(confFile) var conf config.Config err := conf.Load(confFile, testLogConf) - AssertThat(t, err.Error(), EqualTo{"browsers config: parse error: unexpected end of JSON input"}) + assert.Error(t, err) + assert.Equal(t, err.Error(), "browsers config: parse error: unexpected end of JSON input") } func TestConfigEmptyState(t *testing.T) { @@ -68,42 +70,42 @@ func TestConfigEmptyState(t *testing.T) { conf.Load(confFile, testLogConf) state := conf.State(session.NewMap(), 0, 0, 0) - AssertThat(t, state.Total, EqualTo{0}) - AssertThat(t, state.Queued, EqualTo{0}) - AssertThat(t, state.Pending, EqualTo{0}) - AssertThat(t, state.Used, EqualTo{0}) + assert.Equal(t, state.Total, 0) + assert.Equal(t, state.Queued, 0) + assert.Equal(t, state.Pending, 0) + assert.Equal(t, state.Used, 0) } func TestConfigNonEmptyState(t *testing.T) { confFile := configfile(`{}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + _ = conf.Load(confFile, testLogConf) sessions := session.NewMap() sessions.Put("0", &session.Session{Caps: session.Caps{Name: "firefox", Version: "49.0"}, Quota: "unknown"}) state := conf.State(sessions, 1, 0, 0) - AssertThat(t, state.Total, EqualTo{1}) - AssertThat(t, state.Queued, EqualTo{0}) - AssertThat(t, state.Pending, EqualTo{0}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, EqualTo{1}) + assert.Equal(t, state.Total, 1) + assert.Equal(t, state.Queued, 0) + assert.Equal(t, state.Pending, 0) + assert.Equal(t, state.Used, 1) + assert.Equal(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, 1) } func TestConfigEmptyVersions(t *testing.T) { confFile := configfile(`{"firefox":{}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + _ = conf.Load(confFile, testLogConf) sessions := session.NewMap() sessions.Put("0", &session.Session{Caps: session.Caps{Name: "firefox", Version: "49.0"}, Quota: "unknown"}) state := conf.State(sessions, 1, 0, 0) - AssertThat(t, state.Total, EqualTo{1}) - AssertThat(t, state.Queued, EqualTo{0}) - AssertThat(t, state.Pending, EqualTo{0}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, EqualTo{1}) + assert.Equal(t, state.Total, 1) + assert.Equal(t, state.Queued, 0) + assert.Equal(t, state.Pending, 0) + assert.Equal(t, state.Used, 1) + assert.Equal(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, 1) } func TestConfigNonEmptyVersions(t *testing.T) { @@ -115,11 +117,11 @@ func TestConfigNonEmptyVersions(t *testing.T) { sessions := session.NewMap() sessions.Put("0", &session.Session{Caps: session.Caps{Name: "firefox", Version: "49.0"}, Quota: "unknown"}) state := conf.State(sessions, 1, 0, 0) - AssertThat(t, state.Total, EqualTo{1}) - AssertThat(t, state.Queued, EqualTo{0}) - AssertThat(t, state.Pending, EqualTo{0}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, EqualTo{1}) + assert.Equal(t, state.Total, 1) + assert.Equal(t, state.Queued, 0) + assert.Equal(t, state.Pending, 0) + assert.Equal(t, state.Used, 1) + assert.Equal(t, state.Browsers["firefox"]["49.0"]["unknown"].Count, 1) } func TestConfigFindMissingBrowser(t *testing.T) { @@ -129,7 +131,7 @@ func TestConfigFindMissingBrowser(t *testing.T) { conf.Load(confFile, testLogConf) _, _, ok := conf.Find("firefox", "") - AssertThat(t, ok, Is{false}) + assert.False(t, ok) } func TestConfigFindDefaultVersionError(t *testing.T) { @@ -139,65 +141,70 @@ func TestConfigFindDefaultVersionError(t *testing.T) { conf.Load(confFile, testLogConf) _, _, ok := conf.Find("firefox", "") - AssertThat(t, ok, Is{false}) + assert.False(t, ok) } func TestConfigFindDefaultVersion(t *testing.T) { confFile := configfile(`{"firefox":{"default":"49.0"}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + err := conf.Load(confFile, testLogConf) + assert.NoError(t, err) _, v, ok := conf.Find("firefox", "") - AssertThat(t, ok, Is{false}) - AssertThat(t, v, EqualTo{"49.0"}) + assert.False(t, ok) + assert.Equal(t, v, "49.0") } func TestConfigFindFoundByEmptyPrefix(t *testing.T) { confFile := configfile(`{"firefox":{"default":"49.0","versions":{"49.0":{}}}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + err := conf.Load(confFile, testLogConf) + assert.NoError(t, err) _, v, ok := conf.Find("firefox", "") - AssertThat(t, ok, Is{true}) - AssertThat(t, v, EqualTo{"49.0"}) + assert.True(t, ok) + assert.Equal(t, v, "49.0") } func TestConfigFindFoundByPrefix(t *testing.T) { confFile := configfile(`{"firefox":{"default":"49.0","versions":{"49.0":{}}}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + err := conf.Load(confFile, testLogConf) + assert.NoError(t, err) _, v, ok := conf.Find("firefox", "49") - AssertThat(t, ok, Is{true}) - AssertThat(t, v, EqualTo{"49.0"}) + assert.True(t, ok) + assert.Equal(t, v, "49.0") } func TestConfigFindFoundByMatch(t *testing.T) { confFile := configfile(`{"firefox":{"default":"49.0","versions":{"49.0":{}}}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + err := conf.Load(confFile, testLogConf) + assert.NoError(t, err) _, v, ok := conf.Find("firefox", "49.0") - AssertThat(t, ok, Is{true}) - AssertThat(t, v, EqualTo{"49.0"}) + assert.True(t, ok) + assert.Equal(t, v, "49.0") } func TestConfigFindImage(t *testing.T) { confFile := configfile(`{"firefox":{"default":"49.0","versions":{"49.0":{"image":"image","port":"5555", "path":"/"}}}}`) defer os.Remove(confFile) conf := config.NewConfig() - conf.Load(confFile, testLogConf) + err := conf.Load(confFile, testLogConf) + assert.NoError(t, err) b, v, ok := conf.Find("firefox", "49.0") - AssertThat(t, ok, Is{true}) - AssertThat(t, v, EqualTo{"49.0"}) - AssertThat(t, b.Image, EqualTo{"image"}) - AssertThat(t, b.Port, EqualTo{"5555"}) - AssertThat(t, b.Path, EqualTo{"/"}) + assert.True(t, ok) + assert.Equal(t, v, "49.0") + assert.Equal(t, b.Image, "image") + assert.Equal(t, b.Port, "5555") + assert.Equal(t, b.Path, "/") } func TestConfigConcurrentLoad(t *testing.T) { @@ -207,10 +214,10 @@ func TestConfigConcurrentLoad(t *testing.T) { done := make(chan struct{}) go func() { - conf.Load(confFile, testLogConf) + _ = conf.Load(confFile, testLogConf) done <- struct{}{} }() - conf.Load(confFile, testLogConf) + _ = conf.Load(confFile, testLogConf) <-done } @@ -219,15 +226,14 @@ func TestConfigConcurrentLoadAndRead(t *testing.T) { defer os.Remove(confFile) conf := config.NewConfig() err := conf.Load(confFile, testLogConf) - if err != nil { - t.Error(err) - } + assert.NoError(t, err) done := make(chan string) go func() { browser, _, _ := conf.Find("firefox", "") done <- browser.Tmpfs["/tmp"] }() - conf.Load(confFile, testLogConf) + err = conf.Load(confFile, testLogConf) + assert.NoError(t, err) <-done } @@ -236,9 +242,7 @@ func TestConfigConcurrentRead(t *testing.T) { defer os.Remove(confFile) var conf config.Config err := conf.Load(confFile, testLogConf) - if err != nil { - t.Error(err) - } + assert.NoError(t, err) done := make(chan string) go func() { browser, _, _ := conf.Find("firefox", "") diff --git a/go.mod b/go.mod index 61babcd5..3cc5bea9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/aerokube/selenoid go 1.21 require ( - github.com/aandryashin/matchers v0.0.0-20161126170413-435295ea180e github.com/aerokube/ggr v0.0.0-20221124163939-c041f40a7e45 github.com/aerokube/util v1.0.1 github.com/aws/aws-sdk-go v1.44.197 @@ -15,18 +14,22 @@ require ( github.com/mafredri/cdp v0.33.0 github.com/pborman/uuid v1.2.1 github.com/pkg/errors v0.9.1 + github.com/stretchr/testify v1.8.4 golang.org/x/net v0.17.0 ) require ( github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/uuid v1.0.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/mod v0.10.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/tools v0.9.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 559b2c7c..04c78377 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -151,12 +151,14 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g= diff --git a/s3_test.go b/s3_test.go index 7ba0fe69..3ade1170 100644 --- a/s3_test.go +++ b/s3_test.go @@ -13,10 +13,10 @@ import ( "testing" "time" - . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/event" "github.com/aerokube/selenoid/session" "github.com/aerokube/selenoid/upload" + assert "github.com/stretchr/testify/require" ) var ( @@ -75,8 +75,8 @@ func TestS3Uploader(t *testing.T) { Type: "log", } uploaded, err := uploader.Upload(input) - AssertThat(t, err, Is{nil}) - AssertThat(t, uploaded, Is{true}) + assert.NoError(t, err) + assert.True(t, uploaded) } func TestGetKey(t *testing.T) { @@ -93,48 +93,48 @@ func TestGetKey(t *testing.T) { } key := upload.GetS3Key(testPattern, input) - AssertThat(t, key, EqualTo{"some-user/some-Session-id_internet-explorer_11_windows/log.txt"}) + assert.Equal(t, key, "some-user/some-Session-id_internet-explorer_11_windows/log.txt") input.Session.Caps.Name = "" input.Session.Caps.DeviceName = "internet explorer" key = upload.GetS3Key(testPattern, input) - AssertThat(t, key, EqualTo{"some-user/some-Session-id_internet-explorer_11_windows/log.txt"}) + assert.Equal(t, key, "some-user/some-Session-id_internet-explorer_11_windows/log.txt") input.Session.Caps.S3KeyPattern = "$quota/$fileType$fileExtension" key = upload.GetS3Key(testPattern, input) - AssertThat(t, key, EqualTo{"some-user/log.txt"}) + assert.Equal(t, key, "some-user/log.txt") input.Session.Caps.S3KeyPattern = "$fileName" key = upload.GetS3Key(testPattern, input) - AssertThat(t, key, EqualTo{"Some-File.txt"}) + assert.Equal(t, key, "Some-File.txt") } func TestFileMatches(t *testing.T) { matches, err := upload.FileMatches("", "", "any-file-name") - AssertThat(t, err, Is{nil}) - AssertThat(t, matches, Is{true}) + assert.NoError(t, err) + assert.True(t, matches) matches, err = upload.FileMatches("[", "", "/path/to/file.mp4") - AssertThat(t, err, Not{nil}) - AssertThat(t, matches, Is{false}) + assert.Error(t, err) + assert.False(t, matches) matches, err = upload.FileMatches("", "[", "/path/to/file.mp4") - AssertThat(t, err, Not{nil}) - AssertThat(t, matches, Is{false}) + assert.Error(t, err) + assert.False(t, matches) matches, err = upload.FileMatches("*.mp4", "", "/path/to/file.mp4") - AssertThat(t, err, Is{nil}) - AssertThat(t, matches, Is{true}) + assert.NoError(t, err) + assert.True(t, matches) matches, err = upload.FileMatches("*.mp4", "", "/path/to/file.log") - AssertThat(t, err, Is{nil}) - AssertThat(t, matches, Is{false}) + assert.NoError(t, err) + assert.False(t, matches) matches, err = upload.FileMatches("*.mp4", "", "/path/to/file.log") - AssertThat(t, err, Is{nil}) - AssertThat(t, matches, Is{false}) + assert.NoError(t, err) + assert.False(t, matches) matches, err = upload.FileMatches("", "*.log", "/path/to/file.log") - AssertThat(t, err, Is{nil}) - AssertThat(t, matches, Is{false}) + assert.NoError(t, err) + assert.False(t, matches) } diff --git a/selenoid_test.go b/selenoid_test.go index efeac113..357345a1 100644 --- a/selenoid_test.go +++ b/selenoid_test.go @@ -15,12 +15,11 @@ import ( "testing" "time" - . "github.com/aandryashin/matchers" - . "github.com/aandryashin/matchers/httpresp" ggr "github.com/aerokube/ggr/config" "github.com/aerokube/selenoid/config" "github.com/mafredri/cdp" "github.com/mafredri/cdp/rpcc" + assert "github.com/stretchr/testify/require" ) var _ = func() bool { @@ -49,56 +48,52 @@ func TestNewSessionWithGet(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} rsp, err := http.Get(With(srv.URL).Path("/wd/hub/session")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusMethodNotAllowed}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusMethodNotAllowed) + assert.Equal(t, queue.Used(), 0) } func TestBadJsonFormat(t *testing.T) { rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", nil) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) + assert.Equal(t, queue.Used(), 0) } func TestServiceStartupFailure(t *testing.T) { manager = &StartupError{} rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusInternalServerError}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusInternalServerError) + assert.Equal(t, queue.Used(), 0) } func TestBrowserNotFound(t *testing.T) { manager = &BrowserNotFound{} rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) + assert.Equal(t, queue.Used(), 0) } func TestGetDefaultScreenResolution(t *testing.T) { res, err := getScreenResolution("") - AssertThat(t, err, Is{nil}) - AssertThat(t, res, EqualTo{"1920x1080x24"}) + assert.NoError(t, err) + assert.Equal(t, res, "1920x1080x24") } func TestGetFullScreenResolution(t *testing.T) { res, err := getScreenResolution("1024x768x24") - AssertThat(t, err, Is{nil}) - AssertThat(t, res, EqualTo{"1024x768x24"}) + assert.NoError(t, err) + assert.Equal(t, res, "1024x768x24") } func TestGetShortScreenResolution(t *testing.T) { res, err := getScreenResolution("1024x768") - AssertThat(t, err, Is{nil}) - AssertThat(t, res, EqualTo{"1024x768x24"}) + assert.NoError(t, err) + assert.Equal(t, res, "1024x768x24") } func TestTooBigSessionTimeoutCapability(t *testing.T) { @@ -113,52 +108,48 @@ func testBadSessionTimeoutCapability(t *testing.T, timeoutValue string) { manager = &BrowserNotFound{} rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(fmt.Sprintf(`{"desiredCapabilities":{"sessionTimeout":"%s"}}`, timeoutValue)))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) + assert.Equal(t, queue.Used(), 0) } func TestMalformedScreenResolutionCapability(t *testing.T) { manager = &BrowserNotFound{} rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities":{"screenResolution":"bad-resolution"}}`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) + assert.Equal(t, queue.Used(), 0) } func TestGetVideoScreenSizeFromCapability(t *testing.T) { res, err := getVideoScreenSize("1024x768", "anything") - AssertThat(t, err, Is{nil}) - AssertThat(t, res, EqualTo{"1024x768"}) + assert.NoError(t, err) + assert.Equal(t, res, "1024x768") } func TestDetermineVideoScreenSizeFromScreenResolution(t *testing.T) { res, err := getVideoScreenSize("", "1024x768x24") - AssertThat(t, err, Is{nil}) - AssertThat(t, res, EqualTo{"1024x768"}) + assert.NoError(t, err) + assert.Equal(t, res, "1024x768") } func TestMalformedVideoScreenSizeCapability(t *testing.T) { manager = &BrowserNotFound{} rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities":{"videoScreenSize":"bad-size"}}`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) + assert.Equal(t, queue.Used(), 0) } func TestNewSessionNotFound(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} rsp, err := http.Get(With(srv.URL).Path("/wd/hub/session/123")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusNotFound}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusNotFound) + assert.Equal(t, queue.Used(), 0) } func TestNewSessionHostDown(t *testing.T) { @@ -175,13 +166,13 @@ func TestNewSessionHostDown(t *testing.T) { } rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusInternalServerError}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusInternalServerError) canceled = <-ch - AssertThat(t, canceled, Is{true}) + assert.True(t, canceled) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.Equal(t, queue.Used(), 0) } func TestNewSessionBadHostResponse(t *testing.T) { @@ -193,13 +184,12 @@ func TestNewSessionBadHostResponse(t *testing.T) { } rsp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusBadRequest}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusBadRequest) canceled = <-ch - AssertThat(t, canceled, Is{true}) - - AssertThat(t, queue.Used(), EqualTo{0}) + assert.True(t, canceled) + assert.Equal(t, queue.Used(), 0) } func TestSessionCreated(t *testing.T) { @@ -207,16 +197,18 @@ func TestSessionCreated(t *testing.T) { timeout = 5 * time.Second resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities": {"enableVideo": true, "enableVNC": true, "sessionTimeout": "3s"}}`))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sess["sessionId"]) queue.Release() } @@ -225,26 +217,28 @@ func TestSessionCreatedW3C(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"capabilities":{"alwaysMatch":{"acceptInsecureCerts":true, "browserName":"firefox", "browserVersion":"latest", "selenoid:options":{"enableVNC": true}}}}`))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) versions, firefoxPresent := state.Browsers["firefox"] - AssertThat(t, firefoxPresent, Is{true}) + assert.True(t, firefoxPresent) users, versionPresent := versions["latest"] - AssertThat(t, versionPresent, Is{true}) + assert.True(t, versionPresent) userInfo, userPresent := users["unknown"] - AssertThat(t, userPresent, Is{true}) - AssertThat(t, userInfo, Not{nil}) - AssertThat(t, len(userInfo.Sessions), EqualTo{1}) - AssertThat(t, userInfo.Sessions[0].VNC, EqualTo{true}) + assert.True(t, userPresent) + assert.NotNil(t, userInfo) + assert.Len(t, userInfo.Sessions, 1) + assert.True(t, userInfo.Sessions[0].VNC) sessions.Remove(sess["sessionId"]) queue.Release() @@ -254,26 +248,28 @@ func TestSessionCreatedFirstMatchOnly(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"capabilities":{"firstMatch":[{"browserName":"firefox", "browserVersion":"latest", "selenoid:options":{"enableVNC": true}}]}}`))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) versions, firefoxPresent := state.Browsers["firefox"] - AssertThat(t, firefoxPresent, Is{true}) + assert.True(t, firefoxPresent) users, versionPresent := versions["latest"] - AssertThat(t, versionPresent, Is{true}) + assert.True(t, versionPresent) userInfo, userPresent := users["unknown"] - AssertThat(t, userPresent, Is{true}) - AssertThat(t, userInfo, Not{nil}) - AssertThat(t, len(userInfo.Sessions), EqualTo{1}) - AssertThat(t, userInfo.Sessions[0].VNC, EqualTo{true}) + assert.True(t, userPresent) + assert.NotNil(t, userInfo) + assert.Len(t, userInfo.Sessions, 1) + assert.True(t, userInfo.Sessions[0].VNC) sessions.Remove(sess["sessionId"]) queue.Release() @@ -288,16 +284,18 @@ func TestSessionCreatedWdHub(t *testing.T) { manager = &HTTPTest{Handler: root} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sess["sessionId"]) queue.Release() } @@ -306,22 +304,24 @@ func TestSessionWithContentTypeCreatedWdHub(t *testing.T) { root := http.NewServeMux() root.Handle("/wd/hub/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { r.URL.Path = strings.TrimPrefix(r.URL.Path, "/wd/hub") - AssertThat(t, r.Header.Get("Content-Type"), Is{"application/json; charset=utf-8"}) + assert.Equal(t, r.Header.Get("Content-Type"), "application/json; charset=utf-8") Selenium().ServeHTTP(w, r) })) manager = &HTTPTest{Handler: root} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "application/json; charset=utf-8", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sess["sessionId"]) queue.Release() } @@ -333,15 +333,16 @@ func TestSessionFailedAfterTimeout(t *testing.T) { })} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, AllOf{Code{http.StatusInternalServerError}}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusInternalServerError) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 0) + assert.Equal(t, queue.Used(), 0) } func TestClientDisconnected(t *testing.T) { @@ -356,11 +357,12 @@ func TestClientDisconnected(t *testing.T) { cancel() resp, err := http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 0) + assert.Equal(t, queue.Used(), 0) } func TestSessionFailedAfterTwoTimeout(t *testing.T) { @@ -371,15 +373,16 @@ func TestSessionFailedAfterTwoTimeout(t *testing.T) { })} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, AllOf{Code{http.StatusInternalServerError}}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusInternalServerError) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 0) + assert.Equal(t, queue.Used(), 0) } func TestSessionCreatedRedirect(t *testing.T) { @@ -395,19 +398,19 @@ func TestSessionCreatedRedirect(t *testing.T) { manager = &HTTPTest{Handler: root} resp, err := httpClient.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp.StatusCode, Is{http.StatusFound}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusFound) location := resp.Header.Get("Location") - AssertThat(t, resp.StatusCode, Is{Not{""}}) fragments := strings.Split(location, "/") sid := fragments[len(fragments)-1] resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{1}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 1) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sid) queue.Release() } @@ -429,37 +432,38 @@ func TestSessionCreatedRemoveExtensionCapabilities(t *testing.T) { root := http.NewServeMux() root.Handle("/wd/hub/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { err := json.NewDecoder(r.Body).Decode(&browser) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) _, desiredCapabilitiesPresent = browser.Caps["selenoid:options"] _, alwaysMatchPresent = browser.W3CCaps.AlwaysMatch["selenoid:options"] _, chromeOptionsPresent = browser.W3CCaps.AlwaysMatch["goog:chromeOptions"] - AssertThat(t, len(browser.W3CCaps.FirstMatch), EqualTo{1}) + assert.Len(t, browser.W3CCaps.FirstMatch, 1) _, firstMatchPresent = browser.W3CCaps.FirstMatch[0]["selenoid:options"] })) manager = &HTTPTest{Handler: root} resp, err := httpClient.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities": {"browserName": "chrome", "selenoid:options": {"enableVNC": true}}, "capabilities":{"alwaysMatch":{"browserName": "chrome", "goog:chromeOptions": {"args": ["headless"]}, "selenoid:options":{"enableVNC": true}}, "firstMatch": [{"platform": "linux", "selenoid:options": {"enableVideo": true}}]}}`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusOK}) - AssertThat(t, desiredCapabilitiesPresent, Is{false}) - AssertThat(t, alwaysMatchPresent, Is{false}) - AssertThat(t, chromeOptionsPresent, Is{true}) - AssertThat(t, firstMatchPresent, Is{false}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) + assert.False(t, desiredCapabilitiesPresent) + assert.False(t, alwaysMatchPresent) + assert.True(t, chromeOptionsPresent) + assert.False(t, firstMatchPresent) } func TestProxySession(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Get(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url", sess["sessionId"]))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sess["sessionId"]) queue.Release() } @@ -469,13 +473,14 @@ func TestProxySessionPanicOnAbortHandler(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) req, _ := http.NewRequest(http.MethodGet, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url?abort-handler=true", sess["sessionId"])), nil) resp, err = http.DefaultClient.Do(req) - AssertThat(t, err, Not{nil}) + assert.NoError(t, err) sessions.Remove(sess["sessionId"]) queue.Release() @@ -490,39 +495,42 @@ func TestSessionDeleted(t *testing.T) { } resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte(`{"desiredCapabilities": {"enableVideo": true}}`))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) req, _ := http.NewRequest(http.MethodDelete, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s", sess["sessionId"])), nil) http.DefaultClient.Do(req) resp, err = http.Get(With(srv.URL).Path("/status")) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var state config.State - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&state}}) - AssertThat(t, state.Used, EqualTo{0}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&state)) + assert.Equal(t, state.Used, 0) canceled = <-ch - AssertThat(t, canceled, Is{true}) + assert.True(t, canceled) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.Equal(t, queue.Used(), 0) } func TestSessionOnClose(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) req, _ := http.NewRequest(http.MethodDelete, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/window", sess["sessionId"])), nil) - http.DefaultClient.Do(req) + _, _ = http.DefaultClient.Do(req) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.Equal(t, queue.Used(), 1) sessions.Remove(sess["sessionId"]) queue.Release() } @@ -537,29 +545,30 @@ func TestProxySessionCanceled(t *testing.T) { timeout = 100 * time.Millisecond resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) _, ok := sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{true}) + assert.True(t, ok) req, _ := http.NewRequest(http.MethodGet, With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url?timeout=1s", sess["sessionId"])), nil) ctx, cancel := context.WithCancel(context.Background()) req = req.WithContext(ctx) go func() { - http.DefaultClient.Do(req) + _, _ = http.DefaultClient.Do(req) }() <-time.After(50 * time.Millisecond) cancel() <-time.After(100 * time.Millisecond) _, ok = sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{false}) + assert.False(t, ok) canceled = <-ch - AssertThat(t, canceled, Is{true}) + assert.True(t, canceled) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.Equal(t, queue.Used(), 0) } func TestNewSessionTimeout(t *testing.T) { @@ -572,21 +581,22 @@ func TestNewSessionTimeout(t *testing.T) { timeout = 30 * time.Millisecond resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) _, ok := sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{true}) + assert.True(t, ok) <-time.After(50 * time.Millisecond) _, ok = sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{false}) + assert.False(t, ok) canceled = <-ch - AssertThat(t, canceled, Is{true}) + assert.True(t, canceled) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.Equal(t, queue.Used(), 0) } func TestProxySessionTimeout(t *testing.T) { @@ -599,63 +609,63 @@ func TestProxySessionTimeout(t *testing.T) { timeout = 30 * time.Millisecond resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) _, ok := sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{true}) + assert.True(t, ok) <-time.After(20 * time.Millisecond) _, ok = sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{true}) - http.Get(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url", sess["sessionId"]))) + assert.True(t, ok) + _, _ = http.Get(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/url", sess["sessionId"]))) <-time.After(20 * time.Millisecond) _, ok = sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{true}) + assert.True(t, ok) <-time.After(50 * time.Millisecond) _, ok = sessions.Get(sess["sessionId"]) - AssertThat(t, ok, Is{false}) + assert.False(t, ok) canceled = <-ch - AssertThat(t, canceled, Is{true}) + assert.True(t, canceled) - AssertThat(t, queue.Used(), EqualTo{0}) + assert.Equal(t, queue.Used(), 0) } func TestFileUpload(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) fileContents := []byte(`{"file":"UEsDBBQACAgIAJiC4koAAAAAAAAAAAAAAAAJAAAAaGVsbG8udHh080jNyclXCM8vyklRBABQSwcIoxwpHA4AAAAMAAAAUEsBAhQAFAAICAgAmILiSqMcKRwOAAAADAAAAAkAAAAAAAAAAAAAAAAAAAAAAGhlbGxvLnR4dFBLBQYAAAAAAQABADcAAABFAAAAAAA="}`) //Doing two times to test sequential upload resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader(fileContents)) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader(fileContents)) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var jsonResponse map[string]string - - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&jsonResponse}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&jsonResponse)) f, err := os.Open(jsonResponse["value"]) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) content, err := io.ReadAll(f) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) - AssertThat(t, string(content), EqualTo{"Hello World!"}) + assert.Equal(t, string(content), "Hello World!") sessions.Remove(sess["sessionId"]) queue.Release() @@ -665,14 +675,14 @@ func TestFileUploadBadJson(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader([]byte(`malformed json`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusBadRequest}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusBadRequest) sessions.Remove(sess["sessionId"]) queue.Release() @@ -682,14 +692,14 @@ func TestFileUploadNoFile(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader([]byte(`{}`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusBadRequest}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusBadRequest) sessions.Remove(sess["sessionId"]) queue.Release() @@ -699,14 +709,14 @@ func TestFileUploadTwoFiles(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) resp, err = http.Post(With(srv.URL).Path(fmt.Sprintf("/wd/hub/session/%s/file", sess["sessionId"])), "", bytes.NewReader([]byte(`{"file":"UEsDBAoAAAAAAKGJ4koAAAAAAAAAAAAAAAAHABwAb25lLnR4dFVUCQADbv9YWZT/WFl1eAsAAQT1AQAABBQAAABQSwMECgAAAAAApIniSgAAAAAAAAAAAAAAAAcAHAB0d28udHh0VVQJAANz/1hZc/9YWXV4CwABBPUBAAAEFAAAAFBLAQIeAwoAAAAAAKGJ4koAAAAAAAAAAAAAAAAHABgAAAAAAAAAAACkgQAAAABvbmUudHh0VVQFAANu/1hZdXgLAAEE9QEAAAQUAAAAUEsBAh4DCgAAAAAApIniSgAAAAAAAAAAAAAAAAcAGAAAAAAAAAAAAKSBQQAAAHR3by50eHRVVAUAA3P/WFl1eAsAAQT1AQAABBQAAABQSwUGAAAAAAIAAgCaAAAAggAAAAAA"}`))) - AssertThat(t, err, Is{nil}) - AssertThat(t, resp, Code{http.StatusBadRequest}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusBadRequest) sessions.Remove(sess["sessionId"]) queue.Release() @@ -715,99 +725,99 @@ func TestFileUploadTwoFiles(t *testing.T) { func TestPing(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path("/ping")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) - AssertThat(t, rsp.Body, Is{Not{nil}}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) + assert.NotNil(t, rsp.Body) var data map[string]interface{} bt, readErr := io.ReadAll(rsp.Body) - AssertThat(t, readErr, Is{nil}) + assert.NoError(t, readErr) jsonErr := json.Unmarshal(bt, &data) - AssertThat(t, jsonErr, Is{nil}) + assert.NoError(t, jsonErr) _, hasUptime := data["uptime"] - AssertThat(t, hasUptime, Is{true}) + assert.True(t, hasUptime) _, hasLastReloadTime := data["lastReloadTime"] - AssertThat(t, hasLastReloadTime, Is{true}) + assert.True(t, hasLastReloadTime) _, hasNumRequests := data["numRequests"] - AssertThat(t, hasNumRequests, Is{true}) + assert.True(t, hasNumRequests) version, hasVersion := data["version"] - AssertThat(t, hasVersion, Is{true}) - AssertThat(t, version, EqualTo{"test-revision"}) + assert.True(t, hasVersion) + assert.Equal(t, version, "test-revision") } func TestStatus(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path("/wd/hub/status")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) - AssertThat(t, rsp.Body, Is{Not{nil}}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) + assert.NotNil(t, rsp.Body) var data map[string]interface{} bt, readErr := io.ReadAll(rsp.Body) - AssertThat(t, readErr, Is{nil}) + assert.NoError(t, readErr) jsonErr := json.Unmarshal(bt, &data) - AssertThat(t, jsonErr, Is{nil}) + assert.NoError(t, jsonErr) value, hasValue := data["value"] - AssertThat(t, hasValue, Is{true}) + assert.True(t, hasValue) valueMap := value.(map[string]interface{}) ready, hasReady := valueMap["ready"] - AssertThat(t, hasReady, Is{true}) - AssertThat(t, ready, Is{true}) + assert.True(t, hasReady) + assert.Equal(t, ready, true) _, hasMessage := valueMap["message"] - AssertThat(t, hasMessage, Is{true}) + assert.True(t, hasMessage) } func TestServeAndDeleteVideoFile(t *testing.T) { fileName := "testfile" filePath := filepath.Join(videoOutputDir, fileName) - os.WriteFile(filePath, []byte("test-data"), 0644) + _ = os.WriteFile(filePath, []byte("test-data"), 0644) rsp, err := http.Get(With(srv.URL).Path("/video/testfile")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) rsp, err = http.Get(With(srv.URL).Path("/video/?json")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) var files []string - AssertThat(t, rsp, IsJson{&files}) - AssertThat(t, files, EqualTo{[]string{"testfile"}}) + assert.NoError(t, json.NewDecoder(rsp.Body).Decode(&files)) + assert.Equal(t, files, []string{"testfile"}) deleteReq, _ := http.NewRequest(http.MethodDelete, With(srv.URL).Path("/video/testfile"), nil) rsp, err = http.DefaultClient.Do(deleteReq) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) //Deleting already deleted file rsp, err = http.DefaultClient.Do(deleteReq) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusNotFound}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusNotFound) } func TestServeAndDeleteLogFile(t *testing.T) { fileName := "logfile.log" filePath := filepath.Join(logOutputDir, fileName) - os.WriteFile(filePath, []byte("test-data"), 0644) + _ = os.WriteFile(filePath, []byte("test-data"), 0644) rsp, err := http.Get(With(srv.URL).Path("/logs/logfile.log")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) rsp, err = http.Get(With(srv.URL).Path("/logs/?json")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) var files []string - AssertThat(t, rsp, IsJson{&files}) - AssertThat(t, len(files) > 0, Is{true}) + assert.NoError(t, json.NewDecoder(rsp.Body).Decode(&files)) + assert.True(t, len(files) > 0) deleteReq, _ := http.NewRequest(http.MethodDelete, With(srv.URL).Path("/logs/logfile.log"), nil) rsp, err = http.DefaultClient.Do(deleteReq) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) rsp, err = http.DefaultClient.Do(deleteReq) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusNotFound}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusNotFound) } func TestFileDownload(t *testing.T) { @@ -826,17 +836,17 @@ func testFileDownload(t *testing.T, path func(string) string) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) rsp, err := http.Get(With(srv.URL).Path(path(sess["sessionId"]))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) data, err := io.ReadAll(rsp.Body) - AssertThat(t, err, Is{nil}) - AssertThat(t, string(data), EqualTo{"test-data"}) + assert.NoError(t, err) + assert.Equal(t, string(data), "test-data") sessions.Remove(sess["sessionId"]) queue.Release() @@ -844,8 +854,8 @@ func testFileDownload(t *testing.T, path func(string) string) { func TestFileDownloadMissingSession(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path("/download/missing-session/testfile")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusNotFound}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusNotFound) } func TestClipboard(t *testing.T) { @@ -864,21 +874,21 @@ func testClipboard(t *testing.T, path func(string) string) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) rsp, err := http.Get(With(srv.URL).Path(path(sess["sessionId"]))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) data, err := io.ReadAll(rsp.Body) - AssertThat(t, err, Is{nil}) - AssertThat(t, string(data), EqualTo{"test-clipboard-value"}) + assert.NoError(t, err) + assert.Equal(t, string(data), "test-clipboard-value") rsp, err = http.Post(With(srv.URL).Path(path(sess["sessionId"])), "text/plain", bytes.NewReader([]byte("any-data"))) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) sessions.Remove(sess["sessionId"]) queue.Release() @@ -886,18 +896,18 @@ func testClipboard(t *testing.T, path func(string) string) { func TestClipboardMissingSession(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path("/clipboard/missing-session")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusNotFound}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusNotFound) } func TestDevtools(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) u := fmt.Sprintf("ws://%s/devtools/%s", srv.Listener.Addr().String(), sess["sessionId"]) @@ -905,12 +915,12 @@ func TestDevtools(t *testing.T) { defer cancel() conn, err := rpcc.DialContext(ctx, u) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) defer conn.Close() c := cdp.NewClient(conn) err = c.Page.Enable(ctx) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) sessions.Remove(sess["sessionId"]) queue.Release() @@ -920,21 +930,21 @@ func TestAddedSeCdpCapability(t *testing.T) { manager = &HTTPTest{Handler: Selenium()} resp, err := http.Post(With(srv.URL).Path("/wd/hub/session"), "", bytes.NewReader([]byte("{}"))) - AssertThat(t, err, Is{nil}) - + assert.NoError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) var sess map[string]string - AssertThat(t, resp, AllOf{Code{http.StatusOK}, IsJson{&sess}}) + assert.NoError(t, json.NewDecoder(resp.Body).Decode(&sess)) ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) defer cancel() conn, err := rpcc.DialContext(ctx, sess["se:cdp"]) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) defer conn.Close() c := cdp.NewClient(conn) err = c.Page.Enable(ctx) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) sessions.Remove(sess["sessionId"]) queue.Release() @@ -942,16 +952,16 @@ func TestAddedSeCdpCapability(t *testing.T) { func TestParseGgrHost(t *testing.T) { h := parseGgrHost("some-host.example.com:4444") - AssertThat(t, h.Name, EqualTo{"some-host.example.com"}) - AssertThat(t, h.Port, EqualTo{4444}) + assert.Equal(t, h.Name, "some-host.example.com") + assert.Equal(t, h.Port, 4444) } func TestWelcomeScreen(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path("/")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) rsp, err = http.Get(With(srv.URL).Path("/wd/hub")) - AssertThat(t, err, Is{nil}) - AssertThat(t, rsp, Code{http.StatusOK}) + assert.NoError(t, err) + assert.Equal(t, rsp.StatusCode, http.StatusOK) } diff --git a/service_test.go b/service_test.go index b59f6289..86012f16 100644 --- a/service_test.go +++ b/service_test.go @@ -13,13 +13,13 @@ import ( "testing" "time" - . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/config" "github.com/aerokube/selenoid/service" "github.com/aerokube/selenoid/session" "github.com/aerokube/util" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" + assert "github.com/stretchr/testify/require" "golang.org/x/net/websocket" ) @@ -40,8 +40,8 @@ func updateMux(mux http.Handler) { lock.Lock() defer lock.Unlock() mockServer = httptest.NewServer(mux) - os.Setenv("DOCKER_HOST", "tcp://"+hostPort(mockServer.URL)) - os.Setenv("DOCKER_API_VERSION", "1.29") + _ = os.Setenv("DOCKER_HOST", "tcp://"+hostPort(mockServer.URL)) + _ = os.Setenv("DOCKER_API_VERSION", "1.29") cli, _ = client.NewClientWithOpts(client.FromEnv) } @@ -263,18 +263,18 @@ func TestFindDockerIPSpecified(t *testing.T) { func testDocker(t *testing.T, env *service.Environment, cfg *config.Config) { starter := createDockerStarter(t, env, cfg) startedService, err := starter.StartWithCancel() - AssertThat(t, err, Is{nil}) - AssertThat(t, startedService.Url, Not{nil}) - AssertThat(t, startedService.Container, Not{nil}) - AssertThat(t, startedService.Container.ID, EqualTo{"e90e34656806"}) - AssertThat(t, startedService.HostPort.VNC, EqualTo{"127.0.0.1:5900"}) - AssertThat(t, startedService.Cancel, Not{nil}) + assert.NoError(t, err) + assert.NotNil(t, startedService.Url) + assert.NotNil(t, startedService.Container) + assert.Equal(t, startedService.Container.ID, "e90e34656806") + assert.Equal(t, startedService.HostPort.VNC, "127.0.0.1:5900") + assert.NotNil(t, startedService.Cancel) startedService.Cancel() } func createDockerStarter(t *testing.T, env *service.Environment, cfg *config.Config) service.Starter { cli, err := client.NewClientWithOpts(client.FromEnv) - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) manager := service.DefaultManager{Environment: env, Client: cli, Config: cfg} caps := session.Caps{ DeviceName: "firefox", @@ -299,8 +299,8 @@ func createDockerStarter(t *testing.T, env *service.Environment, cfg *config.Con TestName: "my-cool-test", } starter, success := manager.Find(caps, 42) - AssertThat(t, success, Is{true}) - AssertThat(t, starter, Not{nil}) + assert.True(t, success) + assert.NotNil(t, starter) return starter } @@ -334,8 +334,8 @@ func TestDeleteContainerOnStartupError(t *testing.T) { env := testEnvironment() starter := createDockerStarter(t, env, testConfig(env)) _, err := starter.StartWithCancel() - AssertThat(t, err, Not{nil}) - AssertThat(t, numDeleteRequests, EqualTo{1}) + assert.NoError(t, err) + assert.Equal(t, numDeleteRequests, 1) } func TestFindDriver(t *testing.T) { @@ -347,8 +347,8 @@ func TestFindDriver(t *testing.T) { VNC: true, } starter, success := manager.Find(caps, 42) - AssertThat(t, success, Is{true}) - AssertThat(t, starter, Not{nil}) + assert.True(t, success) + assert.NotNil(t, starter) } func TestGetVNC(t *testing.T) { @@ -365,7 +365,7 @@ func TestGetVNC(t *testing.T) { defer sessions.Remove("test-session") u := fmt.Sprintf("ws://%s/vnc/test-session", util.HostPort(srv.URL)) - AssertThat(t, readDataFromWebSocket(t, u), EqualTo{"test-data"}) + assert.Equal(t, readDataFromWebSocket(t, u), "test-data") } func testTCPServer(data string) net.Listener { @@ -376,8 +376,8 @@ func testTCPServer(data string) net.Listener { if err != nil { continue } - io.WriteString(conn, data) - conn.Close() + _, _ = io.WriteString(conn, data) + _ = conn.Close() return } }() @@ -386,12 +386,12 @@ func testTCPServer(data string) net.Listener { func readDataFromWebSocket(t *testing.T, wsURL string) string { ws, err := websocket.Dial(wsURL, "", "http://localhost") - AssertThat(t, err, Is{nil}) + assert.NoError(t, err) var msg = make([]byte, 512) _, err = ws.Read(msg) msg = bytes.Trim(msg, "\x00") - //AssertThat(t, err, Is{nil}) + //assert.NoError(t, err) return string(msg) } @@ -409,5 +409,5 @@ func TestGetLogs(t *testing.T) { defer sessions.Remove("test-session") u := fmt.Sprintf("ws://%s/logs/test-session", util.HostPort(srv.URL)) - AssertThat(t, readDataFromWebSocket(t, u), EqualTo{"test-data"}) + assert.Equal(t, readDataFromWebSocket(t, u), "test-data") } diff --git a/utils_test.go b/utils_test.go index 23d5682a..e6338cd5 100644 --- a/utils_test.go +++ b/utils_test.go @@ -15,12 +15,12 @@ import ( "testing" "time" - . "github.com/aandryashin/matchers" "github.com/aerokube/selenoid/protect" "github.com/aerokube/selenoid/service" "github.com/aerokube/selenoid/session" "github.com/gorilla/websocket" "github.com/pborman/uuid" + assert "github.com/stretchr/testify/require" ) type HTTPTest struct { @@ -199,20 +199,20 @@ func TestProcessExtensionCapabilities(t *testing.T) { }` var caps session.Caps err := json.Unmarshal([]byte(capsJson), &caps) - AssertThat(t, err, Is{nil}) - AssertThat(t, caps.Name, EqualTo{"firefox"}) - AssertThat(t, caps.Version, EqualTo{"57.0"}) - AssertThat(t, caps.TestName, EqualTo{""}) + assert.NoError(t, err) + assert.Equal(t, caps.Name, "firefox") + assert.Equal(t, caps.Version, "57.0") + assert.Equal(t, caps.TestName, "") caps.ProcessExtensionCapabilities() - AssertThat(t, caps.Name, EqualTo{"firefox"}) - AssertThat(t, caps.Version, EqualTo{"57.0"}) - AssertThat(t, caps.DeviceName, EqualTo{"android"}) - AssertThat(t, caps.TestName, EqualTo{"ExampleTestName"}) - AssertThat(t, caps.VNC, EqualTo{true}) - AssertThat(t, caps.VideoFrameRate, EqualTo{uint16(24)}) - AssertThat(t, caps.Env, EqualTo{[]string{"LANG=de_DE.UTF-8"}}) - AssertThat(t, caps.Labels, EqualTo{map[string]string{"key": "value"}}) + assert.Equal(t, caps.Name, "firefox") + assert.Equal(t, caps.Version, "57.0") + assert.Equal(t, caps.DeviceName, "android") + assert.Equal(t, caps.TestName, "ExampleTestName") + assert.True(t, caps.VNC) + assert.Equal(t, caps.VideoFrameRate, uint16(24)) + assert.Equal(t, caps.Env, []string{"LANG=de_DE.UTF-8"}) + assert.Equal(t, caps.Labels, map[string]string{"key": "value"}) } func TestSumUsedTotalGreaterThanPending(t *testing.T) { @@ -230,27 +230,28 @@ func TestSumUsedTotalGreaterThanPending(t *testing.T) { u := srv.URL + "/" _, err := http.Get(u) - AssertThat(t, err, Is{nil}) - AssertThat(t, queue.Pending(), EqualTo{1}) + assert.NoError(t, err) + assert.Equal(t, queue.Pending(), 1) queue.Create() - AssertThat(t, queue.Pending(), EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{1}) + assert.Equal(t, queue.Pending(), 0) + assert.Equal(t, queue.Used(), 1) _, err = http.Get(u) - AssertThat(t, err, Is{nil}) - AssertThat(t, queue.Pending(), EqualTo{1}) + assert.NoError(t, err) + assert.Equal(t, queue.Pending(), 1) queue.Create() - AssertThat(t, queue.Pending(), EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{2}) + assert.Equal(t, queue.Pending(), 0) + assert.Equal(t, queue.Used(), 2) req, _ := http.NewRequest(http.MethodGet, u, nil) - ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() req = req.WithContext(ctx) _, err = http.DefaultClient.Do(req) - AssertThat(t, err, Not{nil}) - AssertThat(t, queue.Pending(), EqualTo{0}) - AssertThat(t, queue.Used(), EqualTo{2}) + assert.NoError(t, err) + assert.Equal(t, queue.Pending(), 0) + assert.Equal(t, queue.Used(), 2) } func TestBrowserName(t *testing.T) { @@ -260,15 +261,15 @@ func TestBrowserName(t *testing.T) { "appium:deviceName": "iPhone 7" }` err := json.Unmarshal([]byte(capsJson), &caps) - AssertThat(t, err, Is{nil}) - AssertThat(t, caps.BrowserName(), EqualTo{"iPhone 7"}) + assert.NoError(t, err) + assert.Equal(t, caps.BrowserName(), "iPhone 7") capsJson = `{ "deviceName": "android 11" }` err = json.Unmarshal([]byte(capsJson), &caps) - AssertThat(t, err, Is{nil}) - AssertThat(t, caps.BrowserName(), EqualTo{"android 11"}) + assert.NoError(t, err) + assert.Equal(t, caps.BrowserName(), "android 11") capsJson = `{ "deviceName": "android 11", @@ -276,6 +277,6 @@ func TestBrowserName(t *testing.T) { "browserName": "firefox" }` err = json.Unmarshal([]byte(capsJson), &caps) - AssertThat(t, err, Is{nil}) - AssertThat(t, caps.BrowserName(), EqualTo{"firefox"}) + assert.NoError(t, err) + assert.Equal(t, caps.BrowserName(), "firefox") }