Skip to content

Commit

Permalink
Add SelectOne() to VizierDBInterface
Browse files Browse the repository at this point in the history
Signed-off-by: Koichiro Den <den@valinux.co.jp>
  • Loading branch information
Koichiro Den committed Dec 4, 2018
1 parent 65c3406 commit 61ac560
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/db/db_init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"fmt"
"log"
)

Expand Down Expand Up @@ -94,3 +95,12 @@ func (d *dbConn) DBInit() {
log.Fatalf("Error creating earlystop_param table: %v", err)
}
}

func (d *dbConn) SelectOne() error {
db := d.db
_, err := db.Exec(`SELECT 1`)
if err != nil {
return fmt.Errorf("Error `SELECT 1` probing: %v", err)
}
return nil
}
2 changes: 2 additions & 0 deletions pkg/db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type WorkerLog struct {

type VizierDBInterface interface {
DBInit()
SelectOne() error

GetStudyConfig(string) (*api.StudyConfig, error)
GetStudyList() ([]string, error)
CreateStudy(*api.StudyConfig) (string, error)
Expand Down
5 changes: 4 additions & 1 deletion pkg/db/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

_ "github.com/go-sql-driver/mysql"
"github.com/golang/protobuf/jsonpb"
"gopkg.in/DATA-DOG/go-sqlmock.v1"

api "github.com/kubeflow/katib/pkg/api"
)
Expand Down Expand Up @@ -48,6 +47,10 @@ func TestMain(m *testing.M) {
mock.ExpectExec("CREATE TABLE IF NOT EXISTS suggestion_param").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS earlystop_param").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
dbInterface.DBInit()
err = dbInterface.SelectOne()
if err != nil {
fmt.Printf("error `SELECT 1` probing: %v\n", err)
}

mysqlAddr := os.Getenv("TEST_MYSQL")
if mysqlAddr != "" {
Expand Down

0 comments on commit 61ac560

Please sign in to comment.