Skip to content

Commit badfcd6

Browse files
author
cglotr
committed
use nicer assertions
1 parent f011a35 commit badfcd6

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.18
55
require (
66
github.com/go-sql-driver/mysql v1.6.0
77
github.com/hooligram/kifu v1.2.4
8+
github.com/stretchr/testify v1.7.2
89
github.com/testcontainers/testcontainers-go v0.11.1
910
)
1011

@@ -15,6 +16,7 @@ require (
1516
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
1617
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68 // indirect
1718
github.com/containerd/containerd v1.5.0-beta.4 // indirect
19+
github.com/davecgh/go-spew v1.1.1 // indirect
1820
github.com/docker/distribution v2.7.1+incompatible // indirect
1921
github.com/docker/docker v20.10.7+incompatible // indirect
2022
github.com/docker/go-connections v0.4.0 // indirect
@@ -31,13 +33,14 @@ require (
3133
github.com/opencontainers/image-spec v1.0.1 // indirect
3234
github.com/opencontainers/runc v1.0.0-rc93 // indirect
3335
github.com/pkg/errors v0.9.1 // indirect
36+
github.com/pmezard/go-difflib v1.0.0 // indirect
3437
github.com/sirupsen/logrus v1.7.0 // indirect
35-
github.com/stretchr/testify v1.7.2 // indirect
3638
go.opencensus.io v0.22.3 // indirect
3739
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
3840
golang.org/x/sys v0.0.0-20210324051608-47abb6519492 // indirect
3941
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
4042
google.golang.org/grpc v1.33.2 // indirect
4143
google.golang.org/protobuf v1.25.0 // indirect
4244
gopkg.in/yaml.v2 v2.4.0 // indirect
45+
gopkg.in/yaml.v3 v3.0.1 // indirect
4346
)

mysqltestcontainer/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Create(databaseName string) (*MySql, error) {
5454
Password: rootPassword,
5555
Ip: host,
5656
Port: p,
57-
Database: databaseName,
57+
DbName: databaseName,
5858
}
5959
return mySql, nil
6060
}

mysqltestcontainer/create_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import (
44
"testing"
55

66
"github.com/arikama/go-mysql-test-container/mysqltestcontainer"
7+
"github.com/stretchr/testify/assert"
78
)
89

910
func TestCreate(t *testing.T) {
1011
mySql, err := mysqltestcontainer.Create("test")
11-
if err != nil {
12-
t.Errorf("Create failed: error=%v", err.Error())
13-
}
12+
13+
assert.Nil(t, err)
14+
assert.NotEmpty(t, mySql.Ip)
15+
assert.NotEmpty(t, mySql.Port)
16+
assert.NotEmpty(t, mySql.Username)
17+
assert.NotEmpty(t, mySql.Password)
18+
assert.NotEmpty(t, mySql.DbName)
19+
assert.NotNil(t, mySql.Db)
20+
1421
err = mySql.Db.Ping()
15-
if err != nil {
16-
t.Errorf("Ping failed: error=%v", err.Error())
17-
}
22+
23+
assert.Nil(t, err)
1824
}

mysqltestcontainer/my_sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ type MySql struct {
88
Password string
99
Ip string
1010
Port string
11-
Database string
11+
DbName string
1212
}

0 commit comments

Comments
 (0)