github.com/MichaelDarr/ahab@v0.0.0-20200528062404-c74c5106e605/internal/helpers_test.go (about) 1 package internal 2 3 import ( 4 "path/filepath" 5 "testing" 6 ) 7 8 const noConfDir = "/mnt/empty" 9 const exampleConfDir = "/mnt/project" 10 const exampleConfPath = "/mnt/project/" + ConfigFileName 11 const exampleConfChildDir = "/mnt/project/src" 12 13 func expectContainerStatus(wantedStatus int, container *Container, t *testing.T) { 14 foundStatus, err := container.Status() 15 if err != nil { 16 t.Errorf("Error checking status: %s", err) 17 } else if foundStatus != wantedStatus { 18 t.Errorf("Unexpected container status %s (expected %s)", ParseStatus(foundStatus), ParseStatus(wantedStatus)) 19 } 20 } 21 22 func prohibitContainerStatus(prohibitStatus int, container *Container, t *testing.T) { 23 foundStatus, err := container.Status() 24 if err != nil { 25 t.Errorf("Error checking status: %s", err) 26 } else if foundStatus == prohibitStatus { 27 t.Errorf("Observed a prohibited container status: %s", ParseStatus(foundStatus)) 28 } 29 } 30 31 func expectStrEq(expected string, actual string, t *testing.T) { 32 if expected != actual { 33 t.Errorf("\nExpected: %s\nActual: %s", expected, actual) 34 } 35 } 36 37 func expectStrsEq(expected *[]string, actual *[]string, t *testing.T) { 38 for i, expect := range *expected { 39 if expect != (*actual)[i] { 40 t.Errorf("\nExpected: %s\nActual: %s", expected, actual) 41 } 42 } 43 } 44 45 // generate a mini container object with a config at path /test/[testDir]/ahab.json 46 func miniContainer(testDir string) *Container { 47 return &Container{ 48 FilePath: filepath.Join("/test", testDir, ConfigFileName), 49 Fields: &Configuration{ 50 AhabVersion: "0.1", 51 ImageURI: "golang:1.13.7-buster", 52 }, 53 } 54 }