|
18 | 18 | package cmd
|
19 | 19 |
|
20 | 20 | import (
|
21 |
| - "fmt" |
| 21 | + "bytes" |
22 | 22 | "testing"
|
23 | 23 |
|
24 | 24 | "github.com/stretchr/testify/assert"
|
25 | 25 | )
|
26 | 26 |
|
27 | 27 | func TestValidate(t *testing.T) {
|
28 | 28 | assert := assert.New(t)
|
| 29 | + b := new(bytes.Buffer) |
| 30 | + rootCmd.SetOut(b) |
| 31 | + rootCmd.SetErr(b) |
29 | 32 | rootCmd.SetArgs([]string{"validate", "--file", "../examples/kubeflow.yaml", "container-canary/kubeflow:shouldpass"})
|
30 | 33 | err := rootCmd.Execute()
|
| 34 | + |
31 | 35 | assert.Nil(err, "should not error")
|
32 |
| - if err != nil { |
33 |
| - fmt.Printf("%+v", err) |
34 |
| - } |
| 36 | + assert.Contains(b.String(), "Validating container-canary/kubeflow:shouldpass against kubeflow", "did not validate") |
| 37 | + assert.Contains(b.String(), "validation passed", "did not pass") |
| 38 | +} |
| 39 | + |
| 40 | +func TestValidateFails(t *testing.T) { |
| 41 | + assert := assert.New(t) |
| 42 | + b := new(bytes.Buffer) |
| 43 | + rootCmd.SetOut(b) |
| 44 | + rootCmd.SetErr(b) |
| 45 | + rootCmd.SetArgs([]string{"validate", "--file", "../examples/kubeflow.yaml", "container-canary/kubeflow:shouldfail"}) |
| 46 | + err := rootCmd.Execute() |
| 47 | + |
| 48 | + assert.NotNil(err, "should fail") |
| 49 | + assert.Contains(b.String(), "validation failed", "did not fail") |
35 | 50 | }
|
36 | 51 |
|
37 | 52 | func TestFileDoesNotExist(t *testing.T) {
|
38 | 53 | assert := assert.New(t)
|
39 |
| - rootCmd.SetArgs([]string{"validate", "--file", "foo.yaml", "container-canary/kubeflow:shouldpass"}) |
| 54 | + b := new(bytes.Buffer) |
| 55 | + rootCmd.SetOut(b) |
| 56 | + rootCmd.SetErr(b) |
| 57 | + rootCmd.SetArgs([]string{"validate", "--file", "foo.yaml", "container-canary/kubeflow:doesnotexist"}) |
40 | 58 | err := rootCmd.Execute()
|
| 59 | + |
41 | 60 | assert.NotNil(err, "did not error")
|
| 61 | + assert.Contains(b.String(), "Cannot find container-canary/kubeflow:doesnotexist", "did not fail") |
42 | 62 | }
|
0 commit comments