Skip to content

Commit

Permalink
add recovery function for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psihachina committed Sep 19, 2022
1 parent 5a8df5b commit 0bb22aa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test-e2e/bastion_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions test-e2e/ecs_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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++ {
Expand All @@ -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++ {
Expand Down Expand Up @@ -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\"")
Expand All @@ -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\"")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions test-e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 0bb22aa

Please sign in to comment.