diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e90af20..bbb8cca 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,3 @@ -# This workflow runs SDK related jobs for OpenMLDB name: SDK on: @@ -34,15 +33,12 @@ jobs: docker compose -f docker-compose.yml exec openmldb-ns1 /opt/openmldb/bin/openmldb --zk_cluster=openmldb-zk:2181 --zk_root_path=/openmldb --role=sql_client --cmd 'SET GLOBAL execute_mode = "online"' - name: go test - env: - OPENMLDB_APISERVER_HOST: 127.0.0.1 - OPENMLDB_APISERVER_PORT: 9527 run: go test ./... -race -covermode=atomic -coverprofile=coverage.out - name: Coverage uses: codecov/codecov-action@v4 with: - files: go/coverage.out + files: coverage.out fail_ci_if_error: true verbose: true token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 06c53df..59fdbb8 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ _testmain.go *.prof output.log + +coverage.out diff --git a/go.mod b/go.mod index 90e3c9e..9ac3cbd 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/4paradigm/OpenMLDB/go +module github.com/4paradigm/openmldb-go-sdk go 1.18 diff --git a/go.sum b/go.sum index b410979..5164829 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/go_sdk_test.go b/go_sdk_test.go index 689a80e..cccd7db 100644 --- a/go_sdk_test.go +++ b/go_sdk_test.go @@ -3,22 +3,21 @@ package openmldb_test import ( "context" "database/sql" + "flag" "fmt" + "log" "os" "testing" // register openmldb driver - _ "github.com/4paradigm/OpenMLDB/go" + _ "github.com/4paradigm/openmldb-go-sdk" "github.com/stretchr/testify/assert" ) -var ( - OPENMLDB_APISERVER_HOST = os.Getenv("OPENMLDB_APISERVER_HOST") - OPENMLDB_APISERVER_PORT = os.Getenv("OPENMLDB_APISERVER_PORT") -) +var apiServer string func Test_driver(t *testing.T) { - db, err := sql.Open("openmldb", fmt.Sprintf("openmldb://%s:%s/test_db", OPENMLDB_APISERVER_HOST, OPENMLDB_APISERVER_PORT)) + db, err := sql.Open("openmldb", fmt.Sprintf("openmldb://%s/test_db", apiServer)) if err != nil { t.Errorf("fail to open connect: %s", err) } @@ -100,3 +99,14 @@ func Test_driver(t *testing.T) { } }) } + +func TestMain(m *testing.M) { + flag.StringVar(&apiServer, "apiserver", "127.0.0.1:9527", "endpoint to apiserver") + flag.Parse() + + if len(apiServer) == 0 { + log.Fatalf("non-empty api server address required") + } + + os.Exit(m.Run()) +}