Skip to content

Commit

Permalink
Fixed Seg Fault and Added Regression Tests (#155)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <[email protected]>
  • Loading branch information
kensipe authored Jul 2, 2020
1 parent 914c2ca commit b6c9fed
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ func (s *Step) Run(namespace string) []error {
}
// test failure processing
s.Logger.Log("test step failed", s.String())
if s.Assert == nil {
return testErrors
}
for _, collector := range s.Assert.Collectors {
s.Logger.Logf("collecting log output for %s", collector.String())
_, err := testutils.RunCommand(context.TODO(), namespace, *collector.Command(), s.Dir, s.Logger, s.Logger, s.Logger, s.Timeout)
Expand Down
51 changes: 51 additions & 0 deletions pkg/test/step_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,54 @@ func TestTwoTestStepping(t *testing.T) {
err = step.LoadYAML("step_integration_test_data/two_step/01-step1.yaml")
assert.Error(t, err, "more than 1 TestStep not allowed in step \"twostepping\"")
}

// intentional testing that a test failure captures the test errors and does not have a segfault
// driving by issue: https://github.com/kudobuilder/kuttl/issues/154
func TestStepFailure(t *testing.T) {
// an assert without setup
var expected runtime.Object = &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"image": "nginx:1.7.9",
"name": "nginx",
},
},
},
},
}

namespace := fmt.Sprintf("kudo-test-%s", petname.Generate(2, "-"))

err := testenv.Client.Create(context.TODO(), testutils.NewResource("v1", "Namespace", namespace, ""))
if !k8serrors.IsAlreadyExists(err) {
// we are ignoring already exists here because in tests we by default use retry client so this can happen
assert.Nil(t, err)
}

//for _, actual := range test.actual {
// _, _, err := testutils.Namespaced(testenv.DiscoveryClient, actual, namespace)
// assert.Nil(t, err)
//
// assert.Nil(t, testenv.Client.Create(context.TODO(), actual))
//}
asserts := []runtime.Object{expected}
step := Step{
Logger: testutils.NewTestLogger(t, ""),
Client: func(bool) (client.Client, error) { return testenv.Client, nil },
DiscoveryClient: func() (discovery.DiscoveryInterface, error) { return testenv.DiscoveryClient, nil },
Asserts: asserts,
Timeout: 1,
}

errs := step.Run(namespace)
assert.Equal(t, len(errs), 1)
}

0 comments on commit b6c9fed

Please sign in to comment.