-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.go
174 lines (144 loc) · 4.47 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package helpers
import (
"context"
"time"
"github.com/stretchr/testify/suite"
"gorm.io/gorm"
"github.com/G-Research/fasttrackml/pkg/api/mlflow/common"
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models"
"github.com/G-Research/fasttrackml/pkg/database"
"github.com/G-Research/fasttrackml/tests/integration/golang/fixtures"
)
var db *gorm.DB
type BaseTestSuite struct {
suite.Suite
AIMClient func() *HttpClient
MlflowClient func() *HttpClient
AdminClient func() *HttpClient
AppFixtures *fixtures.AppFixtures
RunFixtures *fixtures.RunFixtures
TagFixtures *fixtures.TagFixtures
MetricFixtures *fixtures.MetricFixtures
ParamFixtures *fixtures.ParamFixtures
ProjectFixtures *fixtures.ProjectFixtures
DashboardFixtures *fixtures.DashboardFixtures
ExperimentFixtures *fixtures.ExperimentFixtures
DefaultExperiment *models.Experiment
NamespaceFixtures *fixtures.NamespaceFixtures
DefaultNamespace *models.Namespace
ResetOnSubTest bool
SkipCreateDefaultNamespace bool
SkipCreateDefaultExperiment bool
setupHooks []func()
tearDownHooks []func()
}
func (s *BaseTestSuite) runSetupHooks() {
for _, hook := range s.setupHooks {
hook()
}
}
func (s *BaseTestSuite) runTearDownHooks() {
for _, hook := range s.tearDownHooks {
hook()
}
}
func (s *BaseTestSuite) setup() {
s.Require().Nil(s.NamespaceFixtures.TruncateTables())
if !s.SkipCreateDefaultNamespace {
var err error
s.DefaultNamespace, err = s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
Code: "default",
DefaultExperimentID: common.GetPointer(int32(0)),
})
s.Require().Nil(err)
if !s.SkipCreateDefaultExperiment {
s.DefaultExperiment, err = s.ExperimentFixtures.CreateExperiment(context.Background(), &models.Experiment{
Name: "Default",
LifecycleStage: models.LifecycleStageActive,
NamespaceID: s.DefaultNamespace.ID,
})
s.Require().Nil(err)
s.DefaultNamespace.DefaultExperimentID = s.DefaultExperiment.ID
_, err = s.NamespaceFixtures.UpdateNamespace(context.Background(), s.DefaultNamespace)
s.Require().Nil(err)
}
}
}
func (s *BaseTestSuite) tearDown() {
s.Require().Nil(s.NamespaceFixtures.TruncateTables())
}
func (s *BaseTestSuite) AddSetupHook(hook func()) {
s.setupHooks = append(s.setupHooks, hook)
}
func (s *BaseTestSuite) AddTearDownHook(hook func()) {
s.tearDownHooks = append([]func(){hook}, s.tearDownHooks...)
}
func (s *BaseTestSuite) SetupSuite() {
if db == nil {
instance, err := database.NewDBProvider(
GetDatabaseUri(),
1*time.Second,
20,
)
s.Require().Nil(err)
db = instance.GormDB()
}
s.AIMClient = func() *HttpClient {
return NewAimApiClient(GetServiceUri())
}
s.MlflowClient = func() *HttpClient {
return NewMlflowApiClient(GetServiceUri())
}
s.AdminClient = func() *HttpClient {
return NewAdminApiClient(GetServiceUri())
}
appFixtures, err := fixtures.NewAppFixtures(db)
s.Require().Nil(err)
s.AppFixtures = appFixtures
dashboardFixtures, err := fixtures.NewDashboardFixtures(db)
s.Require().Nil(err)
s.DashboardFixtures = dashboardFixtures
experimentFixtures, err := fixtures.NewExperimentFixtures(db)
s.Require().Nil(err)
s.ExperimentFixtures = experimentFixtures
metricFixtures, err := fixtures.NewMetricFixtures(db)
s.Require().Nil(err)
s.MetricFixtures = metricFixtures
namespaceFixtures, err := fixtures.NewNamespaceFixtures(db)
s.Require().Nil(err)
s.NamespaceFixtures = namespaceFixtures
projectFixtures, err := fixtures.NewProjectFixtures(db)
s.Require().Nil(err)
s.ProjectFixtures = projectFixtures
paramFixtures, err := fixtures.NewParamFixtures(db)
s.Require().Nil(err)
s.ParamFixtures = paramFixtures
runFixtures, err := fixtures.NewRunFixtures(db)
s.Require().Nil(err)
s.RunFixtures = runFixtures
tagFixtures, err := fixtures.NewTagFixtures(db)
s.Require().Nil(err)
s.TagFixtures = tagFixtures
s.AddSetupHook(s.setup)
s.AddTearDownHook(s.tearDown)
}
func (s *BaseTestSuite) SetupTest() {
if !s.ResetOnSubTest {
s.runSetupHooks()
}
}
func (s *BaseTestSuite) SetupSubTest() {
if s.ResetOnSubTest {
s.runSetupHooks()
}
}
func (s *BaseTestSuite) TearDownTest() {
if !s.ResetOnSubTest {
s.runTearDownHooks()
}
}
func (s *BaseTestSuite) TearDownSubTest() {
if s.ResetOnSubTest {
s.runTearDownHooks()
}
}