Skip to content

Commit

Permalink
argo: Add unit test (#56)
Browse files Browse the repository at this point in the history
* argo: Add unit test

Signed-off-by: Ce Gao <[email protected]>

* mock: Fix

Signed-off-by: Ce Gao <[email protected]>

* unit: Fix permission

Signed-off-by: Ce Gao <[email protected]>

* db: Fix test cases

Signed-off-by: Ce Gao <[email protected]>

* mock: Regenerate

Signed-off-by: Ce Gao <[email protected]>

* mockgen: Add

Signed-off-by: Ce Gao <[email protected]>

* main_test: Replace mock interface

Signed-off-by: Ce Gao <[email protected]>

* main_test: Mock modelstore

Signed-off-by: Ce Gao <[email protected]>

* bash: Add copyright header

Signed-off-by: Ce Gao <[email protected]>

* scripts: Refactor

Signed-off-by: Ce Gao <[email protected]>

* unit-test: Add ln -s

Signed-off-by: Ce Gao <[email protected]>

* test: Refactor

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Apr 19, 2018
1 parent eb61c8e commit ab09110
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 41 deletions.
9 changes: 5 additions & 4 deletions db/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package db

import (
"fmt"
"github.com/golang/protobuf/jsonpb"
"math/rand"
"os"
"testing"

api "github.com/kubeflow/hp-tuning/api"

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

api "github.com/kubeflow/hp-tuning/api"
)

var db_interface VizierDBInterface
Expand All @@ -33,7 +33,8 @@ func TestMain(m *testing.M) {
mock.ExpectExec("CREATE TABLE IF NOT EXISTS studies").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS study_permissions").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS trials").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS trial_logs").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS trial_metrics").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS trial_lastlogs").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("CREATE TABLE IF NOT EXISTS workers").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))
db_interface.DB_Init()

Expand Down
40 changes: 30 additions & 10 deletions manager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package main

import (
"context"
"testing"

"github.com/golang/mock/gomock"

api "github.com/kubeflow/hp-tuning/api"
//"github.com/kubeflow/hp-tuning/mock/mock_api"
"github.com/kubeflow/hp-tuning/mock/mock_db"
"github.com/kubeflow/hp-tuning/mock/mock_worker_interface"
"testing"
mockdb "github.com/kubeflow/hp-tuning/mock/db"
mockmodelstore "github.com/kubeflow/hp-tuning/mock/modelstore"
mockworker "github.com/kubeflow/hp-tuning/mock/worker"
)

func TestCreateStudy(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDB := mock_db.NewMockVizierDBInterface(ctrl)
mockWif := mock_worker_interface.NewMockWorkerInterface(ctrl)
mockDB := mockdb.NewMockVizierDBInterface(ctrl)
mockWif := mockworker.NewMockWorkerInterface(ctrl)
mockModelStore := mockmodelstore.NewMockModelStore(ctrl)
sid := "teststudy"
sc := &api.StudyConfig{
Name: "test",
Expand All @@ -27,7 +30,16 @@ func TestCreateStudy(t *testing.T) {
mockDB.EXPECT().CreateStudy(
sc,
).Return(sid, nil)
s := &server{wIF: mockWif, StudyChList: make(map[string]studyCh)}
ssr := &api.SaveStudyRequest{
StudyName: "test",
}
mockModelStore.EXPECT().SaveStudy(ssr).Return(nil)

s := &server{
wIF: mockWif,
msIf: mockModelStore,
StudyChList: make(map[string]studyCh),
}
req := &api.CreateStudyRequest{StudyConfig: sc}
ret, err := s.CreateStudy(context.Background(), req)
if err != nil {
Expand All @@ -48,10 +60,18 @@ func TestCreateStudy(t *testing.T) {
func TestGetStudies(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockDB := mock_db.NewMockVizierDBInterface(ctrl)
mockWif := mock_worker_interface.NewMockWorkerInterface(ctrl)
mockDB := mockdb.NewMockVizierDBInterface(ctrl)
mockWif := mockworker.NewMockWorkerInterface(ctrl)
mockModelStore := mockmodelstore.NewMockModelStore(ctrl)
sid := []string{"teststudy1", "teststudy2"}
s := &server{wIF: mockWif, StudyChList: map[string]studyCh{sid[0]: studyCh{}, sid[1]: studyCh{}}}
s := &server{
wIF: mockWif,
msIf: mockModelStore,
StudyChList: map[string]studyCh{
sid[0]: studyCh{},
sid[1]: studyCh{},
},
}
dbIf = mockDB

sc := []*api.StudyConfig{
Expand Down
122 changes: 106 additions & 16 deletions mock/mock_api/manager_mock.go → mock/api/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mock/mock_api/suggestion_mock.go → mock/api/suggestion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mock/mock_db/db_mock.go → mock/db/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions mock/modelstore/modelstore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ab09110

Please sign in to comment.