@@ -61,7 +61,8 @@ func mainE() error {
61
61
return fmt .Errorf ("failed to create output directory: %w" , err )
62
62
}
63
63
64
- logPath := filepath .Join (* outPath , fmt .Sprintf ("%s_benchi.log" , time .Now ().Format ("20060102150405" )))
64
+ now := time .Now ()
65
+ logPath := filepath .Join (* outPath , fmt .Sprintf ("%s_benchi.log" , now .Format ("20060102150405" )))
65
66
logFile , err := os .Create (logPath )
66
67
if err != nil {
67
68
return fmt .Errorf ("failed to create log file: %w" , err )
@@ -88,14 +89,28 @@ func mainE() error {
88
89
slog .Info ("Using network" , "network" , net .Name , "network-id" , net .ID )
89
90
defer dockerutil .RemoveNetwork (ctx , dockerClient , net .Name )
90
91
92
+ // Resolve absolute path before changing working directory
93
+ * outPath , err = filepath .Abs (* outPath )
94
+ if err != nil {
95
+ return fmt .Errorf ("failed to get absolute path for output directory: %w" , err )
96
+ }
97
+
91
98
// Change working directory to config path, all relative paths are relative to the config file.
92
99
err = os .Chdir (filepath .Dir (* configPath ))
93
100
if err != nil {
94
101
return fmt .Errorf ("could not change working directory: %w" , err )
95
102
}
96
103
104
+ tr := benchi .BuildTestRunners (cfg , benchi.TestRunnerOptions {
105
+ ResultsDir : * outPath ,
106
+ StartedAt : now ,
107
+ FilterTests : nil ,
108
+ FilterTools : nil ,
109
+ DockerClient : dockerClient ,
110
+ })
111
+
97
112
// TODO run all tests
98
- model , err := newTestModel (cfg , dockerClient )
113
+ model , err := newTestModel (dockerClient , tr [ 0 ] )
99
114
if err != nil {
100
115
return fmt .Errorf ("failed to create test model: %w" , err )
101
116
}
@@ -118,25 +133,30 @@ func parseConfig() (config.Config, error) {
118
133
}
119
134
120
135
type testModel struct {
121
- config config.Config
122
- tool string
136
+ runner * benchi.TestRunner
137
+ errors []error
138
+ currentStep benchi.Step
123
139
124
140
infrastructureModel * composeProjectModel
125
141
toolsModel * composeProjectModel
126
142
}
127
143
128
- func newTestModel (cfg config.Config , client client.APIClient ) (tea.Model , error ) {
129
- infraFiles := make ([]string , 0 , len (cfg .Infrastructure ))
130
- for _ , f := range cfg .Infrastructure {
144
+ type stepResult struct {
145
+ err error
146
+ }
147
+
148
+ func newTestModel (client client.APIClient , runner * benchi.TestRunner ) (tea.Model , error ) {
149
+ infraFiles := make ([]string , 0 , len (runner .Infrastructure ()))
150
+ for _ , f := range runner .Infrastructure () {
131
151
infraFiles = append (infraFiles , f .DockerCompose )
132
152
}
133
153
infraComposeProject , err := benchi .NewComposeProject (infraFiles , client )
134
154
if err != nil {
135
155
return nil , err
136
156
}
137
157
138
- toolFiles := make ([]string , 0 , len (cfg .Tools ))
139
- for _ , f := range cfg .Tools {
158
+ toolFiles := make ([]string , 0 , len (runner .Tools () ))
159
+ for _ , f := range runner .Tools () {
140
160
toolFiles = append (toolFiles , f .DockerCompose )
141
161
}
142
162
toolComposeProject , err := benchi .NewComposeProject (toolFiles , client )
@@ -145,8 +165,7 @@ func newTestModel(cfg config.Config, client client.APIClient) (tea.Model, error)
145
165
}
146
166
147
167
return & testModel {
148
- config : cfg ,
149
- tool : "conduit" ,
168
+ runner : runner ,
150
169
151
170
infrastructureModel : & composeProjectModel {
152
171
name : "Infrastructure" ,
@@ -160,7 +179,14 @@ func newTestModel(cfg config.Config, client client.APIClient) (tea.Model, error)
160
179
}
161
180
162
181
func (m * testModel ) Init () tea.Cmd {
163
- return tea .Batch (m .infrastructureModel .Init (), m .toolsModel .Init ())
182
+ return tea .Batch (m .infrastructureModel .Init (), m .toolsModel .Init (), m .step ())
183
+ }
184
+
185
+ func (m * testModel ) step () tea.Cmd {
186
+ return func () tea.Msg {
187
+ err := m .runner .RunStep (context .Background ())
188
+ return stepResult {err : err }
189
+ }
164
190
}
165
191
166
192
func (m * testModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
@@ -179,13 +205,22 @@ func (m *testModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
179
205
}
180
206
181
207
return m , tea .Batch (cmds ... )
208
+ case stepResult :
209
+ if msg .err != nil {
210
+ m .errors = append (m .errors , msg .err )
211
+ }
212
+ m .currentStep = m .runner .Step ()
213
+ if m .currentStep != benchi .StepDone {
214
+ return m , m .step ()
215
+ }
182
216
}
183
217
184
218
return m , nil
185
219
}
186
220
187
221
func (m * testModel ) View () string {
188
- s := "Running test Foo (1/3)"
222
+ s := fmt .Sprintf ("Running test %s (1/3)" , m .runner .Name ())
223
+ s = fmt .Sprintf ("Step: %s" , m .currentStep )
189
224
s += "\n \n "
190
225
s += m .infrastructureModel .View ()
191
226
s += "\n "
0 commit comments