Skip to content

Commit

Permalink
test: clean code and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Gągor committed Dec 28, 2024
1 parent 4b547fe commit 193add8
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions tests/tests_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package tests_test

import (
// "bytes"
// "fmt"
// "regexp"
// "strings"
"os"
"testing"

Expand All @@ -18,15 +14,6 @@ import (
"github.com/gruntwork-io/terratest/modules/shell"
)

// var cmd shell.Command

// func TestMain(m *testing.M) {

// exitVal := m.Run()

// os.Exit(exitVal)
// }

func cmd(args ...string) shell.Command {
defaultArgs := []string{}
return shell.Command{
Expand All @@ -50,15 +37,14 @@ func TestRunTDVersion(t *testing.T) {
}

func TestCase1(t *testing.T) {
// t.Parallel()
t.Parallel()

cmd := cmd(
"--no-color",
"--config", "test-1.yaml",
"--tag", "v1.1.1",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-1")
Expand Down Expand Up @@ -97,12 +83,13 @@ func TestCase2(t *testing.T) {
"--verbose",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-2")
assert.Contains(t, out, "Building image=test-case-2b")

// FIXME: improve labels verification
// not all of them match but should
assert.Contains(t, out, "\"maintainer\":\"Tomasz Gągor <[email protected]>\"")
assert.Contains(t, out, "\"org.opencontainers.image.authors\":\"Tomasz Gągor <[email protected]>\"")
// assert.Contains(t, out, "org.opencontainers.image.branch")
Expand Down Expand Up @@ -136,17 +123,16 @@ func TestCase3(t *testing.T) {
"--tag", "v3.3.3",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.NotNil(t, err) // should fail
assert.Contains(t, out, "Building image=test-case-3")
assert.Contains(t, out, "No 'tags' defined for image=test-case-3")
assert.Contains(t, out, "building without 'tags', would just overwrite images in place, which is pointless - add 'tags' block to continue")

// do not fail
// should fail
code, err := shell.GetExitCodeForRunCommandError(err)
assert.Nil(t, err)
assert.NotEqual(t, code, 0) // should fail
assert.NotEqual(t, code, 0)
}

func TestCase4(t *testing.T) {
Expand All @@ -159,7 +145,6 @@ func TestCase4(t *testing.T) {
"--delete",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-4")
Expand All @@ -180,7 +165,6 @@ func TestCase5(t *testing.T) {
"--delete",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-5")
Expand All @@ -203,7 +187,6 @@ func TestCase6(t *testing.T) {
"--delete",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-6")
Expand All @@ -225,7 +208,6 @@ func TestCase7(t *testing.T) {
"--delete",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-7")
Expand All @@ -249,7 +231,6 @@ func TestCase8(t *testing.T) {
"--delete",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-8")
Expand All @@ -272,7 +253,6 @@ func TestCase9(t *testing.T) {
"--tag", "v9.9.9",
)

// returns what I want
out, err := shell.RunCommandAndGetOutputE(t, cmd)
assert.Nil(t, err)
assert.Contains(t, out, "Building image=test-case-9")
Expand Down

0 comments on commit 193add8

Please sign in to comment.