From 7943734395d5a8aad22b9b6668c9e673b4c57ed1 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 10 Aug 2020 17:40:33 +0200 Subject: [PATCH 1/7] Update linter --- .gitlab-ci.yml | 3 +-- .golangci.toml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5999a1..0782757 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,13 +36,12 @@ vendor: lint: stage: test - image: golang:1.14 + image: golangci/golangci-lint:v1.30 services: [] before_script: - '' script: - go mod download - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.7 - golangci-lint run ./... go-1.9: diff --git a/.golangci.toml b/.golangci.toml index 2949d72..d3c929a 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -3,7 +3,7 @@ format = "colored-line-number" [linters] enable = [ - "interfacer", "gocyclo", "unconvert", "goimports", "unused", "varcheck", + "gocyclo", "unconvert", "goimports", "unused", "varcheck", "vetshadow", "misspell", "nakedret", "errcheck", "golint", "ineffassign", "deadcode", "goconst", "vet", "unparam", "gofmt" ] From 8fb3b4346c7ca5130ca1ebb636db43a3934f6149 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 19 Oct 2020 22:09:24 +0200 Subject: [PATCH 2/7] Pass the proper database name during replicaiton test setup --- client/replicate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/replicate.go b/client/replicate.go index 5c5edd8..18f40f2 100644 --- a/client/replicate.go +++ b/client/replicate.go @@ -45,7 +45,7 @@ func testReplication(ctx *kt.Context, client *kivik.Client) { defer ctx.DestroyDB(dbtarget) defer ctx.DestroyDB(dbsource) - db := ctx.Admin.DB(context.Background(), dbsource) + db := ctx.Admin.DB(context.Background(), ctx.TestDB()) if err := db.Err(); err != nil { ctx.Fatalf("Failed to open db: %s", err) } From e5712fb14fd2cbbc33239675704a46015ce49e58 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Tue, 3 Nov 2020 21:57:14 +0100 Subject: [PATCH 3/7] Fix cleanup of replications --- client/replicate.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/replicate.go b/client/replicate.go index 18f40f2..bb0b478 100644 --- a/client/replicate.go +++ b/client/replicate.go @@ -40,10 +40,13 @@ func testReplication(ctx *kt.Context, client *kivik.Client) { case "none": prefix = "" } - dbtarget := prefix + ctx.TestDB() - dbsource := prefix + ctx.TestDB() - defer ctx.DestroyDB(dbtarget) - defer ctx.DestroyDB(dbsource) + targetDB, sourceDB := ctx.TestDB(), ctx.TestDB() + defer func() { + ctx.DestroyDB(targetDB) + ctx.DestroyDB(sourceDB) + }() + dbtarget := prefix + targetDB + dbsource := prefix + sourceDB db := ctx.Admin.DB(context.Background(), ctx.TestDB()) if err := db.Err(); err != nil { From 1de3014965c9be1ce31b573a6642696fb2f63efa Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 9 Nov 2020 22:24:12 +0100 Subject: [PATCH 4/7] Clean up replication source databases properly --- client/replicate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/replicate.go b/client/replicate.go index bb0b478..d4d6d99 100644 --- a/client/replicate.go +++ b/client/replicate.go @@ -48,7 +48,7 @@ func testReplication(ctx *kt.Context, client *kivik.Client) { dbtarget := prefix + targetDB dbsource := prefix + sourceDB - db := ctx.Admin.DB(context.Background(), ctx.TestDB()) + db := ctx.Admin.DB(context.Background(), sourceDB) if err := db.Err(); err != nil { ctx.Fatalf("Failed to open db: %s", err) } From 99588bc663524b5ab05a8ac8ec0a0c70f65c1cc7 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 26 Oct 2020 22:08:19 +0100 Subject: [PATCH 5/7] Simplify replication url tests --- client/replicate.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/replicate.go b/client/replicate.go index d4d6d99..82d5fa1 100644 --- a/client/replicate.go +++ b/client/replicate.go @@ -183,10 +183,10 @@ func doReplicationTest(ctx *kt.Context, client *kivik.Client, dbtarget, dbsource } source := stripCreds(dbsource) target := stripCreds(dbtarget) - if rep.Source != source && rep.Source != source+"/" { + if rep.Source != source { ctx.Errorf("Unexpected source. Expected: %s, Actual: %s\n", source, rep.Source) } - if rep.Target != target && rep.Target != target+"/" { + if rep.Target != target { ctx.Errorf("Unexpected target. Expected: %s, Actual: %s\n", target, rep.Target) } if rep.State() != kivik.ReplicationComplete { @@ -202,5 +202,6 @@ func doReplicationTest(ctx *kt.Context, client *kivik.Client, dbtarget, dbsource func stripCreds(addr string) string { url, _ := url.Parse(addr) url.User = nil - return url.String() + url.Path = strings.TrimSuffix(url.Path, "/") + return url.String() + "/" } From 4b85eb6d999c60fcc9404075f4e6225c76caf96d Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 26 Oct 2020 22:13:16 +0100 Subject: [PATCH 6/7] Test with Go 1.15 --- .gitlab-ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0782757..e1a5699 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,7 +36,7 @@ vendor: lint: stage: test - image: golangci/golangci-lint:v1.30 + image: golangci/golangci-lint:v1.32 services: [] before_script: - '' @@ -70,6 +70,10 @@ go-1.14: <<: *test_template image: golang:1.14 +go-1.15: + <<: *test_template + image: golang:1.15 + go-rc: <<: *test_template image: golang:rc From 60839c2baa432a4e83def111c89f66d46299a268 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Sun, 1 Nov 2020 21:07:02 +0100 Subject: [PATCH 7/7] More consistent replication URL checking It seems CouchDB is inconsistent in what URL format it returns, so this tries to compensate. --- .gitlab-ci.yml | 2 +- client/replicate.go | 44 +++++++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e1a5699..c8b98ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,7 +36,7 @@ vendor: lint: stage: test - image: golangci/golangci-lint:v1.32 + image: golangci/golangci-lint:v1.30 services: [] before_script: - '' diff --git a/client/replicate.go b/client/replicate.go index 82d5fa1..8ad4958 100644 --- a/client/replicate.go +++ b/client/replicate.go @@ -4,7 +4,9 @@ import ( "context" "net/http" "net/url" + "path/filepath" "strings" + "testing" "time" kivik "github.com/go-kivik/kivik/v3" @@ -181,14 +183,8 @@ func doReplicationTest(ctx *kt.Context, client *kivik.Client, dbtarget, dbsource ctx.Errorf("Expected a replication ID") } } - source := stripCreds(dbsource) - target := stripCreds(dbtarget) - if rep.Source != source { - ctx.Errorf("Unexpected source. Expected: %s, Actual: %s\n", source, rep.Source) - } - if rep.Target != target { - ctx.Errorf("Unexpected target. Expected: %s, Actual: %s\n", target, rep.Target) - } + checkReplicationURL(ctx.T, "source", dbsource, rep.Source) + checkReplicationURL(ctx.T, "target", dbtarget, rep.Target) if rep.State() != kivik.ReplicationComplete { ctx.Errorf("Replication failed to complete. Final state: %s\n", rep.State()) } @@ -199,9 +195,31 @@ func doReplicationTest(ctx *kt.Context, client *kivik.Client, dbtarget, dbsource return success } -func stripCreds(addr string) string { - url, _ := url.Parse(addr) - url.User = nil - url.Path = strings.TrimSuffix(url.Path, "/") - return url.String() + "/" +func checkReplicationURL(t *testing.T, name, want, got string) { + wantURL, err := url.Parse(want) + if err != nil { + t.Fatal(err) + } + gotURL, err := url.Parse(got) + if err != nil { + t.Fatal(err) + } + if !replicationURLsEqual(wantURL, gotURL) { + t.Errorf("Unexpected %s URL. Want: %s, got %s", name, want, got) + } +} + +func replicationURLsEqual(want, got *url.URL) bool { + if want.User != nil && got.User != nil { + wantUser := want.User.Username() + gotUser := got.User.Username() + if wantUser != "" && gotUser != "" && wantUser != gotUser { + return false + } + } + want.User = nil + got.User = nil + want.Path = filepath.Join(want.Path, "") + got.Path = filepath.Join(got.Path, "") + return want.String() == got.String() }