From 0bb22aa87065a542a7652d26342fd2b0133b8ed0 Mon Sep 17 00:00:00 2001 From: psihachina Date: Mon, 19 Sep 2022 16:11:11 +0300 Subject: [PATCH] add recovery function for e2e tests --- test-e2e/bastion_tunnel_test.go | 10 ++++++++++ test-e2e/ecs_apps_test.go | 20 ++++++++++++++++++++ test-e2e/util.go | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/test-e2e/bastion_tunnel_test.go b/test-e2e/bastion_tunnel_test.go index 8ce27f26..71f7bb2d 100644 --- a/test-e2e/bastion_tunnel_test.go +++ b/test-e2e/bastion_tunnel_test.go @@ -36,6 +36,8 @@ func TestIzeUpInfra(t *testing.T) { t.Fatalf("No ize.toml file in project template path %s", examplesRootDir) } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("up", "infra") @@ -62,6 +64,8 @@ func TestIzeTunnelUp(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("tunnel", "up") @@ -86,6 +90,8 @@ func TestIzeTunnelStatus(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("tunnel", "status") @@ -108,6 +114,8 @@ func TestIzeTunnelDown(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("tunnel", "down") @@ -130,6 +138,8 @@ func TestIzeDown(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("down", "--auto-approve") diff --git a/test-e2e/ecs_apps_test.go b/test-e2e/ecs_apps_test.go index c288b59c..2783d1ed 100644 --- a/test-e2e/ecs_apps_test.go +++ b/test-e2e/ecs_apps_test.go @@ -129,6 +129,8 @@ func TestIzeUpInfra(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + foundIZEConfig := false err := filepath.Walk(examplesRootDir, func(path string, info fs.FileInfo, err error) error { if err != nil { @@ -174,6 +176,8 @@ func TestIzeUpGoblin(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + foundIZEConfig := false err := filepath.Walk(examplesRootDir, func(path string, info fs.FileInfo, err error) error { if err != nil { @@ -216,6 +220,8 @@ func TestIzeUpSquibby(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + foundIZEConfig := false err := filepath.Walk(examplesRootDir, func(path string, info fs.FileInfo, err error) error { if err != nil { @@ -255,6 +261,8 @@ func TestIzeUpSquibby(t *testing.T) { } func TestCheckSecretsSquibby(t *testing.T) { + defer recovery(t) + url := fmt.Sprintf("http://squibby.%s.examples.ize.sh/", os.Getenv("ENV")) for i := 0; i < 10; i++ { @@ -281,6 +289,8 @@ func TestCheckSecretsSquibby(t *testing.T) { } func TestCheckSecretsGoblin(t *testing.T) { + defer recovery(t) + url := fmt.Sprintf("http://goblin.%s.examples.ize.sh/", os.Getenv("ENV")) for i := 0; i < 10; i++ { @@ -309,6 +319,8 @@ func TestIzeExecGoblin(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunPty("--plain-text", "exec", "goblin", "--", "sh -c \"echo $APP_NAME\"") @@ -331,6 +343,8 @@ func TestIzeExecSquibby(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunPty("--plain-text", "exec", "squibby", "--", "sh -c \"echo $APP_NAME\"") @@ -353,6 +367,8 @@ func TestIzeSecretsRmGoblin(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + rand.Seed(time.Now().UTC().UnixNano()) b := make([]byte, 12) @@ -403,6 +419,8 @@ func TestIzeSecretsRmSquibby(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + rand.Seed(time.Now().UTC().UnixNano()) b := make([]byte, 12) @@ -456,6 +474,8 @@ func TestIzeDown(t *testing.T) { t.Fatalf("Missing required environment variable IZE_EXAMPLES_PATH") } + defer recovery(t) + ize := NewBinary(t, izeBinary, examplesRootDir) stdout, stderr, err := ize.RunRaw("down", "--auto-approve") diff --git a/test-e2e/util.go b/test-e2e/util.go index 81a11a41..d1402557 100644 --- a/test-e2e/util.go +++ b/test-e2e/util.go @@ -97,3 +97,9 @@ func (b *binary) Run(args string) (stdout string) { func splitArgs(args string) []string { return strings.Split(args, " ") } + +func recovery(t *testing.T) { + if panicMsg := recover(); panicMsg != nil { + t.Errorf("panic message: %s\n", panicMsg) + } +}