Skip to content

Commit

Permalink
Ensure config file contains required params (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
symm authored Jul 2, 2017
1 parent 313ca8f commit a24a123
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"time"
)
Expand All @@ -29,7 +28,8 @@ func main() {

smokeTests, err := parseVapefile(*vapeFile)
if err != nil {
log.Fatal(err)
fmt.Printf("Error reading config: %s", err.Error())
os.Exit(1)
}

testsLen := len(smokeTests)
Expand All @@ -53,10 +53,9 @@ func main() {
}

if passedCount < testsLen {
fmt.Println("\n🔥 Some tests failed. you may have a bad deployment")
fmt.Println("\n🔥 Some tests failed. You may have a bad deployment")
os.Exit(2)
}

fmt.Printf("\n✨ [%d/%d] tests passed in %s\n", passedCount, testsLen, time.Since(start))

}
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func parseVapefile(file string) (SmokeTests, error) {
if err != nil {
return nil, err
}

for _, test := range tests {
if test.URI == "" || test.ExpectedStatusCode == 0 {
return nil, fmt.Errorf("Each test should have at least a uri and expected_status_code:\n %v", string(raw))
}

}

return tests, nil
}

Expand Down
53 changes: 51 additions & 2 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"io/ioutil"
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -50,11 +51,11 @@ func TestReadVapefileSuccess(t *testing.T) {
json := `[
{
"uri": "/status/200",
"expectedStatusCode": 200
"expected_status_code": 200
},
{
"uri": "/status/500",
"expectedStatusCode": 500
"expected_status_code": 500
}
]`
tmpfile, cleanup, err := tmpFile(json)
Expand All @@ -68,6 +69,54 @@ func TestReadVapefileSuccess(t *testing.T) {
}
}

func TestReadVapefileMissingFields(t *testing.T) {
t.Run("TestUriMissing", func(t *testing.T) {
json := `[
{
"expected_status_code": 200
}
]`
tmpfile, cleanup, err := tmpFile(json)
if err != nil {
t.Fatal(err)
}
defer cleanup()
_, err = parseVapefile(tmpfile.Name())
if err == nil {
t.Errorf("expected error: got: %v", err)
}

expectedError := "Each test should have at least a uri and expected_status_code"
if strings.Contains(err.Error(), expectedError) == false {
t.Errorf("expected message: %s got %s", expectedError, err.Error())
}
})

t.Run("TestExpectedStatusCodeMissing", func(t *testing.T) {
t.Run("TestUriMissing", func(t *testing.T) {
json := `[
{
"uri": "/health"
}
]`
tmpfile, cleanup, err := tmpFile(json)
if err != nil {
t.Fatal(err)
}
defer cleanup()
_, err = parseVapefile(tmpfile.Name())
if err == nil {
t.Errorf("expected error: got: %v", err)
}

expectedError := "Each test should have at least a uri and expected_status_code"
if strings.Contains(err.Error(), expectedError) == false {
t.Errorf("expected message: %s got %s", expectedError, err.Error())
}
})
})
}

func TestParseBaseURL(t *testing.T) {
t.Run("TestInvalidURL", func(t *testing.T) {
url := ":"
Expand Down

0 comments on commit a24a123

Please sign in to comment.