Improve logging in e2e tests

This commit is contained in:
Tomasz Sęk 2020-01-02 12:43:48 +01:00
parent f10d20cf4b
commit 45e91be07c
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
2 changed files with 19 additions and 4 deletions

View File

@ -44,6 +44,13 @@ func setupTest(t *testing.T) (string, *framework.TestCtx) {
t.Fatalf("could not initialize cluster resources: %v", err)
}
defer func() {
showLogsIfTestHasFailed(t, ctx)
if t.Failed() && ctx != nil {
ctx.Cleanup()
}
}()
jenkinsServiceList := &v1alpha2.JenkinsList{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha2.Kind,

View File

@ -125,7 +125,7 @@ func printKubernetesPods(t *testing.T, namespace string) {
}
}
func showLogsAndCleanup(t *testing.T, ctx *framework.TestCtx) {
func showLogsIfTestHasFailed(t *testing.T, ctx *framework.TestCtx) {
namespace, err := ctx.GetNamespace()
if err != nil {
t.Fatalf("Failed to get '%s' namespace", err)
@ -134,14 +134,22 @@ func showLogsAndCleanup(t *testing.T, ctx *framework.TestCtx) {
if t.Failed() {
t.Log("Test failed. Bellow here you can check logs:")
printOperatorLogs(t, namespace)
printKubernetesEvents(t, namespace)
printKubernetesPods(t, namespace)
printOperatorLogs(t, namespace)
}
}
func showLogsAndCleanup(t *testing.T, ctx *framework.TestCtx) {
namespace, err := ctx.GetNamespace()
if err != nil {
t.Fatalf("Failed to get '%s' namespace", err)
}
showLogsIfTestHasFailed(t, ctx)
ctx.Cleanup()
err = waitUntilNamespaceDestroyed(namespace)
if err != nil {
if err = waitUntilNamespaceDestroyed(namespace); err != nil {
t.Fatalf("Failed to wait for namespace until destroyed '%s'", err)
}
}