From 73672b52755a5af90d47c1b84d358a40e9bc2a56 Mon Sep 17 00:00:00 2001 From: DanRoscigno Date: Wed, 7 Feb 2024 13:14:54 -0500 Subject: [PATCH 1/3] open DB connection once in BeforeSuite Signed-off-by: DanRoscigno --- ci/docs_suite_test.go | 7 +++++++ ci/docs_test.go | 21 --------------------- ci/helper.go | 9 --------- ci/quickstart_basic_test.go | 25 ------------------------- 4 files changed, 7 insertions(+), 55 deletions(-) diff --git a/ci/docs_suite_test.go b/ci/docs_suite_test.go index c235b23..f92527b 100644 --- a/ci/docs_suite_test.go +++ b/ci/docs_suite_test.go @@ -11,3 +11,10 @@ func TestDocs(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Docs Suite") } + +var _ = BeforeSuite(func() { + By("Connecting to StarRocks FE") + db, _ = GetDSNConnection() + db.SetMaxOpenConns(1) + Expect(db.Ping()).Should(Succeed()) +}) diff --git a/ci/docs_test.go b/ci/docs_test.go index aed3568..60832f7 100644 --- a/ci/docs_test.go +++ b/ci/docs_test.go @@ -1,16 +1,12 @@ package docs_test import ( - "database/sql" "fmt" "os" "strings" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - //"time" -// "github.com/go-sql-driver/mysql" ) var _ = Describe("Docs", func() { @@ -18,23 +14,6 @@ var _ = Describe("Docs", func() { AWS_S3_SECRET_KEY := os.Getenv("AWS_S3_SECRET_KEY") When("Loading from S3 docs/loading/s3", Ordered, func() { - var db *sql.DB - - //cfg := mysql.Config{ - //User: "root", - //Passwd: "", - //Net: "tcp", - //Addr: "fe:9030", - //AllowNativePasswords: true, - //} - - BeforeAll(func() { - By("Connecting to StarRocks FE") - //db, _ = sql.Open("mysql", cfg.FormatDSN()) - db, _ = GetDSNConnection() - db.SetMaxOpenConns(1) - Expect(db.Ping()).Should(Succeed()) - }) AfterAll(func() { var err error diff --git a/ci/helper.go b/ci/helper.go index f3809c2..94b4406 100644 --- a/ci/helper.go +++ b/ci/helper.go @@ -3,15 +3,6 @@ package docs_test import ( "database/sql" -// "net/url" -// "fmt" -// "os" -// "strings" - -// . "github.com/onsi/ginkgo/v2" -// . "github.com/onsi/gomega" - - //"time" "github.com/go-sql-driver/mysql" ) var db *sql.DB diff --git a/ci/quickstart_basic_test.go b/ci/quickstart_basic_test.go index 21c55bb..7658664 100644 --- a/ci/quickstart_basic_test.go +++ b/ci/quickstart_basic_test.go @@ -1,33 +1,16 @@ package docs_test import ( - "database/sql" - //"log" "fmt" "os" "os/exec" - //"strings" - -// "github.com/go-sql-driver/mysql" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) var _ = Describe("QuickstartBasic", func() { - //AWS_S3_ACCESS_KEY := os.Getenv("AWS_S3_ACCESS_KEY") - //AWS_S3_SECRET_KEY := os.Getenv("AWS_S3_SECRET_KEY") - When("Running the basic Quick Start", Ordered, func() { - var db *sql.DB - - //cfg := mysql.Config{ - //User: "root", - //Passwd: "", - //Net: "tcp", - //Addr: "fe:9030", - //AllowNativePasswords: true, - //} BeforeAll(func() { // download the crash data in /tmp/ dir @@ -46,14 +29,6 @@ var _ = Describe("QuickstartBasic", func() { err = WeatherCurl.Wait() Expect(err).ToNot(HaveOccurred()) - // Connect to the database - By("Connecting to StarRocks FE") - //db, _ = sql.Open("mysql", cfg.FormatDSN()) - db, _ = GetDSNConnection() - db.SetMaxOpenConns(1) - Expect(err).ToNot(HaveOccurred()) - Expect(db.Ping()).Should(Succeed()) - }) AfterAll(func() { From 3a19d1a484ddf7ab2568025704b6ef312a46a99a Mon Sep 17 00:00:00 2001 From: DanRoscigno Date: Wed, 7 Feb 2024 14:29:48 -0500 Subject: [PATCH 2/3] add fxn to real SQL from file Signed-off-by: DanRoscigno --- ci/helper.go | 10 ++++++++++ ci/quickstart_basic_test.go | 16 +++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ci/helper.go b/ci/helper.go index 94b4406..4fb7b31 100644 --- a/ci/helper.go +++ b/ci/helper.go @@ -3,6 +3,8 @@ package docs_test import ( "database/sql" + "os" + "fmt" "github.com/go-sql-driver/mysql" ) var db *sql.DB @@ -18,3 +20,11 @@ func GetDSNConnection() (*sql.DB, error) { return sql.Open("mysql", cfg.FormatDSN()) } +func SQLFromFile(filename string) string { + bytes, err := os.ReadFile(filename) + if err != nil { + fmt.Print(err) + } + return string(bytes) +} + diff --git a/ci/quickstart_basic_test.go b/ci/quickstart_basic_test.go index 7658664..f7445b3 100644 --- a/ci/quickstart_basic_test.go +++ b/ci/quickstart_basic_test.go @@ -53,16 +53,18 @@ var _ = Describe("QuickstartBasic", func() { It("DDL: Create quickstart tables", func() { By("creating the crash data table") - b, err := os.ReadFile("SQL/quickstart/basic/NYPD_table.sql") - if err != nil { - fmt.Print(err) - } - SQL := string(b) - _, err = db.Exec(SQL) + // I need a function in helper.go that takes a string (file path/name) + // and returns the SQL from the file as a string. + //b, err := os.ReadFile("SQL/quickstart/basic/NYPD_table.sql") + //if err != nil { + //fmt.Print(err) + //} + SQL := SQLFromFile("SQL/quickstart/basic/NYPD_table.sql") + _, err := db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) By("creating the weather data table") - b, err = os.ReadFile("SQL/quickstart/basic/Weather_table.sql") + b, err := os.ReadFile("SQL/quickstart/basic/Weather_table.sql") if err != nil { fmt.Print(err) } From 031d5f6138a3e68f29d02851529575a8c4b96b69 Mon Sep 17 00:00:00 2001 From: DanRoscigno Date: Wed, 7 Feb 2024 14:39:16 -0500 Subject: [PATCH 3/3] add fxn to read SQL from file Signed-off-by: DanRoscigno --- ci/quickstart_basic_test.go | 40 ++++++------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/ci/quickstart_basic_test.go b/ci/quickstart_basic_test.go index f7445b3..a778217 100644 --- a/ci/quickstart_basic_test.go +++ b/ci/quickstart_basic_test.go @@ -1,8 +1,6 @@ package docs_test import ( - "fmt" - "os" "os/exec" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -53,22 +51,12 @@ var _ = Describe("QuickstartBasic", func() { It("DDL: Create quickstart tables", func() { By("creating the crash data table") - // I need a function in helper.go that takes a string (file path/name) - // and returns the SQL from the file as a string. - //b, err := os.ReadFile("SQL/quickstart/basic/NYPD_table.sql") - //if err != nil { - //fmt.Print(err) - //} SQL := SQLFromFile("SQL/quickstart/basic/NYPD_table.sql") _, err := db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) By("creating the weather data table") - b, err := os.ReadFile("SQL/quickstart/basic/Weather_table.sql") - if err != nil { - fmt.Print(err) - } - SQL = string(b) + SQL = SQLFromFile("SQL/quickstart/basic/Weather_table.sql") _, err = db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) }) @@ -91,38 +79,22 @@ var _ = Describe("QuickstartBasic", func() { It("should be able to query tables", func() { By("querying the crash data table") - b, err := os.ReadFile("SQL/quickstart/basic/CrashesPerHour.sql") - if err != nil { - fmt.Print(err) - } - SQL := string(b) - _, err = db.Exec(SQL) + SQL := SQLFromFile("SQL/quickstart/basic/CrashesPerHour.sql") + _, err := db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) By("querying the weather data table") - b, err = os.ReadFile("SQL/quickstart/basic/AverageTemp.sql") - if err != nil { - fmt.Print(err) - } - SQL = string(b) + SQL = SQLFromFile("SQL/quickstart/basic/AverageTemp.sql") _, err = db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) By("JOINing to see impact of low visibility") - b, err = os.ReadFile("SQL/quickstart/basic/LowVisibility.sql") - if err != nil { - fmt.Print(err) - } - SQL = string(b) + SQL = SQLFromFile("SQL/quickstart/basic/LowVisibility.sql") _, err = db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) By("JOINing to see impact of icy weather") - b, err = os.ReadFile("SQL/quickstart/basic/Icy.sql") - if err != nil { - fmt.Print(err) - } - SQL = string(b) + SQL = SQLFromFile("SQL/quickstart/basic/Icy.sql") _, err = db.Exec(SQL) Expect(err).ToNot(HaveOccurred()) })