Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: James Lamb <[email protected]>
  • Loading branch information
jameslamb committed Aug 1, 2024
1 parent 4fb07fc commit bc83110
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test: ## Run tests
testprep: ## Run test prerequisite tasks
docker build -t container-canary/kubeflow:shouldpass -f internal/testdata/containers/kubeflow.Dockerfile .
docker build -t container-canary/kubeflow:shouldfail -f internal/testdata/containers/kubeflow_broken.Dockerfile .
docker build -t container-canary/long-sleep:local - < internal/testdata/containers/long-sleep.Dockerfile

version:
@echo version: $(VERSION)
Expand Down
12 changes: 12 additions & 0 deletions cmd/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ func TestFileDoesNotExist(t *testing.T) {
assert.NotNil(err, "did not error")
assert.Contains(b.String(), "Cannot find container-canary/kubeflow:doesnotexist", "did not fail")
}

func TestValidateRespectsStartupTimeout(t *testing.T) {
assert := assert.New(t)
b := new(bytes.Buffer)
rootCmd.SetOut(b)
rootCmd.SetErr(b)
rootCmd.SetArgs([]string{"validate", "--file", "../examples/kubeflow.yaml", "container-canary/long-sleep:local", "--startup-timeout", "3"})
err := rootCmd.Execute()

assert.NotNil(err, "should fail")
assert.Contains(b.String(), "validation failed", "container failed to start after 3 seconds")
}
3 changes: 3 additions & 0 deletions internal/testdata/containers/long-sleep.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine

CMD [ "sleep", "60" ]
1 change: 0 additions & 1 deletion internal/validator/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func handleConfigLoaded(m model, msg configLoaded) (model, tea.Cmd) {
if !m.tty {
commands = append(commands, tea.Printf("Starting container"))
}
// right here... m.container isn't set yet
commands = append(commands, startContainer(m.image, m.validator, m.containerStartupTimeout))
return m, tea.Batch(commands...)
}
Expand Down

0 comments on commit bc83110

Please sign in to comment.