Skip to content

Commit

Permalink
Merge pull request #926 from go-kivik/testMatrix
Browse files Browse the repository at this point in the history
Switch to matrix for main Go tests
  • Loading branch information
flimzy committed Apr 8, 2024
2 parents 13291c1 + 4a1c390 commit 8bb96e0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 68 deletions.
86 changes: 35 additions & 51 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,44 @@ variables:
COUCHDB_USER: admin
COUCHDB_PASSWORD: abc123

.test: &go_test_template
test:
parallel:
matrix:
- COUCHVER: ["2.2.0", "2.3.1", "3.0.1", "3.1.2", "3.2.3", "3.3.3"]
GOVER: ["1.17", "1.18", "1.19", "1.20", "1.21", "1.22"]
stage: test
image: golang:$GOVER
services:
- name: couchdb:2.2.0
alias: couch22
- name: apache/couchdb:2.3.1
alias: couch23
- name: couchdb:3.0.1
alias: couch30
- name: couchdb:3.1.2
alias: couch31
- name: couchdb:3.2.3
alias: couch32
- name: couchdb:3.3.3
alias: couch33
variables:
KIVIK_TEST_DSN_COUCH22: http:https://admin:abc123@couch22:5984/
KIVIK_TEST_DSN_COUCH23: http:https://admin:abc123@couch23:5984/
KIVIK_TEST_DSN_COUCH30: http:https://admin:abc123@couch30:5984/
KIVIK_TEST_DSN_COUCH31: http:https://admin:abc123@couch31:5984/
KIVIK_TEST_DSN_COUCH32: http:https://admin:abc123@couch32:5984/
KIVIK_TEST_DSN_COUCH33: http:https://admin:abc123@couch33:5984/
- name: couchdb:$COUCHVER
alias: couch$COUCHVER
before_script:
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH22}
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH23}
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH30}
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH31}
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH32}
- ./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH33}
- |
case $COUCHVER in
"2.2.0")
export KIVIK_TEST_DSN_COUCH22=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH22}
;;
"2.3.1")
export KIVIK_TEST_DSN_COUCH23=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH23}
;;
"3.0.1")
export KIVIK_TEST_DSN_COUCH30=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH30}
;;
"3.1.2")
export KIVIK_TEST_DSN_COUCH31=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH31}
;;
"3.2.3")
export KIVIK_TEST_DSN_COUCH32=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH32}
;;
"3.3.3")
export KIVIK_TEST_DSN_COUCH33=http:https://$COUCHDB_USER:[email protected]:5984/
./script/complete_couch2.sh ${KIVIK_TEST_DSN_COUCH33}
;;
esac
script:
- go mod download
- go test -race -shuffle=on ./...
Expand All @@ -59,32 +68,7 @@ coverage:
- go mod download
- ./script/coverage.sh

go-1.17:
<<: *go_test_template
image: golang:1.17

go-1.18:
<<: *go_test_template
image: golang:1.18

go-1.19:
<<: *go_test_template
image: golang:1.19

go-1.20:
<<: *go_test_template
image: golang:1.20

go-1.21:
<<: *go_test_template
image: golang:1.21

go-1.22:
<<: *go_test_template
image: golang:1.22

.gopherjs_test: &gopherjs_test_template
<<: *go_test_template
image: golang:1.18
services:
- name: couchdb:3.3.3
Expand Down
2 changes: 1 addition & 1 deletion couchdb/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func realDB(t *testing.T) *db {

func realDBConnect(t *testing.T) (*db, error) {
driver := &couch{}
c, err := driver.NewClient(kt.DSN(t), OptionNoRequestCompression())
c, err := driver.NewClient(kt.DSN3(t), OptionNoRequestCompression())
if err != nil {
return nil, err
}
Expand Down
15 changes: 7 additions & 8 deletions kiviktest/kt/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (
kivik "github.com/go-kivik/kivik/v4"
)

// DSN returns a testing DSN from the environment.
func DSN(t *testing.T) string {
// DSN3 returns a testing DSN from the environment for CouchDB 3.x.
func DSN3(t *testing.T) string {
for _, env := range []string{
"KIVIK_TEST_DSN",
"KIVIK_TEST_DSN_COUCH33",
"KIVIK_TEST_DSN_COUCH32", "KIVIK_TEST_DSN_COUCH31",
"KIVIK_TEST_DSN_COUCH30", "KIVIK_TEST_DSN_COUCH23",
"KIVIK_TEST_DSN_COUCH22",
"KIVIK_TEST_DSN_COUCH32",
"KIVIK_TEST_DSN_COUCH31",
"KIVIK_TEST_DSN_COUCH30",
} {
dsn := os.Getenv(env)
if dsn != "" {
Expand All @@ -40,7 +39,7 @@ func DSN(t *testing.T) string {

// NoAuthDSN returns a testing DSN with credentials stripped.
func NoAuthDSN(t *testing.T) string {
dsn := DSN(t)
dsn := DSN3(t)
parsed, err := url.Parse(dsn)
if err != nil {
t.Fatalf("invalid DSN: %s", err)
Expand All @@ -59,7 +58,7 @@ func connect(dsn string, t *testing.T) *kivik.Client {

// GetClient returns a connection to a CouchDB client, for testing.
func GetClient(t *testing.T) *kivik.Client {
return connect(DSN(t), t)
return connect(DSN3(t), t)
}

// GetNoAuthClient returns an unauthenticated connection to a CouchDB client, for testing.
Expand Down
16 changes: 8 additions & 8 deletions replicate_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
}
tests := testy.NewTable()
tests.Add("couch to couch", func(t *testing.T) interface{} {
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
if err != nil {
t.Fatal(err)
}
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
if err != nil {
t.Fatal(err)
}
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
}
})
tests.Add("couch to couch with sec", func(t *testing.T) interface{} {
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
if err != nil {
t.Fatal(err)
}
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
if err != nil {
t.Fatal(err)
}
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
t.Fatal(err)
}

dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestReplicate_live(t *testing.T) { //nolint:gocyclo // allowed for subtests
if err != nil {
t.Fatal(err)
}
dsn := kt.DSN(t)
dsn := kt.DSN3(t)
client, err := kivik.New("couch", dsn)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 8bb96e0

Please sign in to comment.