Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure config file contains required params #17

Merged
merged 1 commit into from
Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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