From 5b95428ff7b2d9653626577c6d14c5e3ee69152d Mon Sep 17 00:00:00 2001 From: Mohsen Mirzakhani Date: Tue, 26 Sep 2023 21:32:30 +0200 Subject: [PATCH] rename golang sdk package (#20) --- .github/workflows/tag_go_sdk.yaml | 19 +++++++++++++++++++ clients/{golang => dbctlgo}/client.go | 2 +- clients/{golang => dbctlgo}/client_test.go | 14 ++++++++------ clients/dbctlgo/go.mod | 11 +++++++++++ clients/{golang => dbctlgo}/go.sum | 0 clients/{golang => dbctlgo}/options.go | 2 +- clients/golang/go.mod | 8 -------- .../test_sql/fixtures/00_add_some_records.sql | 0 .../test_sql/schema/migrations.up.sql | 0 docs/testing/golang.md | 15 ++++++++++----- 10 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/tag_go_sdk.yaml rename clients/{golang => dbctlgo}/client.go (99%) rename clients/{golang => dbctlgo}/client_test.go (87%) create mode 100644 clients/dbctlgo/go.mod rename clients/{golang => dbctlgo}/go.sum (100%) rename clients/{golang => dbctlgo}/options.go (99%) delete mode 100644 clients/golang/go.mod rename clients/{golang => }/test_sql/fixtures/00_add_some_records.sql (100%) rename clients/{golang => }/test_sql/schema/migrations.up.sql (100%) diff --git a/.github/workflows/tag_go_sdk.yaml b/.github/workflows/tag_go_sdk.yaml new file mode 100644 index 0000000..2c696a2 --- /dev/null +++ b/.github/workflows/tag_go_sdk.yaml @@ -0,0 +1,19 @@ +name: Tag Golang SDK +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + +jobs: + job: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v6 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.ref.replace('/v', '/clients/dbctlgo/v'), + sha: context.sha + }); diff --git a/clients/golang/client.go b/clients/dbctlgo/client.go similarity index 99% rename from clients/golang/client.go rename to clients/dbctlgo/client.go index 99d4c45..deb4597 100644 --- a/clients/golang/client.go +++ b/clients/dbctlgo/client.go @@ -1,4 +1,4 @@ -package golang +package dbctlgo import ( "bytes" diff --git a/clients/golang/client_test.go b/clients/dbctlgo/client_test.go similarity index 87% rename from clients/golang/client_test.go rename to clients/dbctlgo/client_test.go index 2644a69..734cbbc 100644 --- a/clients/golang/client_test.go +++ b/clients/dbctlgo/client_test.go @@ -1,17 +1,19 @@ -package golang +package dbctlgo_test import ( "database/sql" "testing" - // golang postgres driver + "github.com/gomodule/redigo/redis" - _ "github.com/gomodule/redigo/redis" + "github.com/mirzakhany/clients/dbctlgo" + + // golang postgres driver _ "github.com/lib/pq" ) func TestMustCreatePostgresDB(t *testing.T) { - uri := MustCreatePostgresDB(t, WithMigrations("./test_sql/schema")) + uri := dbctlgo.MustCreatePostgresDB(t, dbctlgo.WithMigrations("../test_sql/schema")) if uri == "" { t.Fatal("url is empty") } @@ -51,7 +53,7 @@ func TestMustCreatePostgresDB(t *testing.T) { } func TestPostgresDBWithFixtures(t *testing.T) { - uri := MustCreatePostgresDB(t, WithMigrations("./test_sql/schema"), WithFixtures("./test_sql/fixtures")) + uri := dbctlgo.MustCreatePostgresDB(t, dbctlgo.WithMigrations("../test_sql/schema"), dbctlgo.WithFixtures("../test_sql/fixtures")) if uri == "" { t.Fatal("url is empty") } @@ -94,7 +96,7 @@ func TestPostgresDBWithFixtures(t *testing.T) { } func TestRedis(t *testing.T) { - uri := MustCreateRedisDB(t) + uri := dbctlgo.MustCreateRedisDB(t) if uri == "" { t.Fatal("url is empty") } diff --git a/clients/dbctlgo/go.mod b/clients/dbctlgo/go.mod new file mode 100644 index 0000000..ee71a17 --- /dev/null +++ b/clients/dbctlgo/go.mod @@ -0,0 +1,11 @@ +module github.com/mirzakhany/dbctl/clients/golang/dbctl + +go 1.21.0 + +require ( + github.com/gomodule/redigo v1.8.9 + github.com/lib/pq v1.10.9 + github.com/mirzakhany/clients/dbctlgo v0.0.0-unpublished +) + +replace github.com/mirzakhany/clients/dbctlgo v0.0.0-unpublished => ./ diff --git a/clients/golang/go.sum b/clients/dbctlgo/go.sum similarity index 100% rename from clients/golang/go.sum rename to clients/dbctlgo/go.sum diff --git a/clients/golang/options.go b/clients/dbctlgo/options.go similarity index 99% rename from clients/golang/options.go rename to clients/dbctlgo/options.go index c0257f3..fc2e8f9 100644 --- a/clients/golang/options.go +++ b/clients/dbctlgo/options.go @@ -1,4 +1,4 @@ -package golang +package dbctlgo import ( "fmt" diff --git a/clients/golang/go.mod b/clients/golang/go.mod deleted file mode 100644 index 119f3cb..0000000 --- a/clients/golang/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/mirzakhany/dbctl/clients/golang - -go 1.21.0 - -require ( - github.com/gomodule/redigo v1.8.9 - github.com/lib/pq v1.10.9 -) diff --git a/clients/golang/test_sql/fixtures/00_add_some_records.sql b/clients/test_sql/fixtures/00_add_some_records.sql similarity index 100% rename from clients/golang/test_sql/fixtures/00_add_some_records.sql rename to clients/test_sql/fixtures/00_add_some_records.sql diff --git a/clients/golang/test_sql/schema/migrations.up.sql b/clients/test_sql/schema/migrations.up.sql similarity index 100% rename from clients/golang/test_sql/schema/migrations.up.sql rename to clients/test_sql/schema/migrations.up.sql diff --git a/docs/testing/golang.md b/docs/testing/golang.md index f8bae1e..e91b099 100644 --- a/docs/testing/golang.md +++ b/docs/testing/golang.md @@ -11,6 +11,11 @@ dbclt testing -- pg Use sdk in test: +Install the sdk: +```shell +go get github.com/mirzakhany/clients/dbctlgo +``` + ```golang package foo @@ -18,13 +23,13 @@ import ( "database/sql" "testing" - dbctl "github.com/mirzakhany/dbctl/clients/golang" + "github.com/mirzakhany/clients/dbctlgo" // golang postgres driver _ "github.com/lib/pq" ) func TestMustCreatePostgresDB(t *testing.T) { - uri := dbctl.MustCreatePostgresDB(t) + uri := dbctlgo.MustCreatePostgresDB(t) if uri == "" { t.Fatal("url is empty") } @@ -57,7 +62,7 @@ func TestMustCreatePostgresDB(t *testing.T) { We can also apply migrations before starting the test. ```golang func TestMustCreatePostgresDB(t *testing.T) { - uri := dbctl.MustCreatePostgresDB(t, dbctl.WithMigrations("./test_sql/schema"), dbctl.WithFixtures("./test_sql/fixtures")) + uri := dbctlgo.MustCreatePostgresDB(t, dbctlgo.WithMigrations("./test_sql/schema"), dbctlgo.WithFixtures("./test_sql/fixtures")) if uri == "" { t.Fatal("url is empty") } @@ -85,12 +90,12 @@ import ( "database/sql" "testing" - dbctl "github.com/mirzakhany/dbctl/clients/golang" + "github.com/mirzakhany/clients/dbctlgo" "github.com/gomodule/redigo/redis" ) func TestRedis(t *testing.T) { - uri := dbctl.MustCreateRedisDB(t) + uri := dbctlgo.MustCreateRedisDB(t) if uri == "" { t.Fatal("url is empty") }