Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argo: Add unit test #56

Merged
merged 12 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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