Skip to content

Commit

Permalink
Merge pull request #17 from DanRoscigno/init-common
Browse files Browse the repository at this point in the history
open DB connection once in BeforeSuite
  • Loading branch information
DanRoscigno authored Feb 7, 2024
2 parents bf3f037 + 031d5f6 commit f2de2cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 89 deletions.
7 changes: 7 additions & 0 deletions ci/docs_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
21 changes: 0 additions & 21 deletions ci/docs_test.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
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() {
AWS_S3_ACCESS_KEY := os.Getenv("AWS_S3_ACCESS_KEY")
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
Expand Down
19 changes: 10 additions & 9 deletions ci/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ package docs_test

import (
"database/sql"
// "net/url"
// "fmt"
// "os"
// "strings"

// . "github.com/onsi/ginkgo/v2"
// . "github.com/onsi/gomega"

//"time"
"os"
"fmt"
"github.com/go-sql-driver/mysql"
)
var db *sql.DB
Expand All @@ -27,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)
}

67 changes: 8 additions & 59 deletions ci/quickstart_basic_test.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
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
Expand All @@ -46,14 +27,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() {
Expand All @@ -78,20 +51,12 @@ 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)
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())
})
Expand All @@ -114,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())
})
Expand Down

0 comments on commit f2de2cc

Please sign in to comment.