Skip to content

Commit

Permalink
Update tests for invlaid --gateway URL to use got/want in error messa…
Browse files Browse the repository at this point in the history
…ge, and better naming

Signed-off-by: Eric Stoekl <[email protected]>
  • Loading branch information
ericstoekl authored and alexellis committed Nov 2, 2017
1 parent fa9e08d commit b606487
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions proxy/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package proxy

import (
"fmt"
"net/http"

"testing"
Expand Down Expand Up @@ -55,15 +56,16 @@ func Test_DeleteFunction_Not2xxAnd404(t *testing.T) {
}
}

func Test_DeleteFunction_BadURL(t *testing.T) {
func Test_DeleteFunction_MissingURLPrefix(t *testing.T) {
url := "127.0.0.1:8080"

stdout := test.CaptureStdout(func() {
DeleteFunction(url, "function-to-delete")
})

r := regexp.MustCompile(`(?m:first path segment in URL cannot contain colon)`)
expectedErrMsg := "first path segment in URL cannot contain colon"
r := regexp.MustCompile(fmt.Sprintf("(?m:%s)", expectedErrMsg))
if !r.MatchString(stdout) {
t.Fatalf("Output not matched: %s", stdout)
t.Fatalf("Want: %s\nGot: %s", expectedErrMsg, stdout)
}
}
8 changes: 5 additions & 3 deletions proxy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package proxy

import (
"fmt"
"net/http"

"testing"
Expand Down Expand Up @@ -75,7 +76,7 @@ func Test_DeployFunction_Not2xx(t *testing.T) {
}
}

func Test_DeployFunction_BadURL(t *testing.T) {
func Test_DeployFunction_MissingURLPrefix(t *testing.T) {
url := "127.0.0.1:8080"

stdout := test.CaptureStdout(func() {
Expand All @@ -95,8 +96,9 @@ func Test_DeployFunction_BadURL(t *testing.T) {
)
})

r := regexp.MustCompile(`(?m:first path segment in URL cannot contain colon)`)
expectedErrMsg := "first path segment in URL cannot contain colon"
r := regexp.MustCompile(fmt.Sprintf("(?m:%s)", expectedErrMsg))
if !r.MatchString(stdout) {
t.Fatalf("Output not matched: %s", stdout)
t.Fatalf("Want: %s\nGot: %s", expectedErrMsg, stdout)
}
}
8 changes: 5 additions & 3 deletions proxy/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package proxy

import (
"fmt"
"net/http"

"testing"
Expand Down Expand Up @@ -54,7 +55,7 @@ func Test_InvokeFunction_Not2xx(t *testing.T) {
}
}

func Test_InvokeFunction_BadURL(t *testing.T) {
func Test_InvokeFunction_MissingURLPrefix(t *testing.T) {

bytesIn := []byte("test data")
_, err := InvokeFunction(
Expand All @@ -69,8 +70,9 @@ func Test_InvokeFunction_BadURL(t *testing.T) {
t.Fatalf("Error was not returned")
}

r := regexp.MustCompile(`(?m:cannot connect to OpenFaaS on URL: )`)
expectedErrMsg := "cannot connect to OpenFaaS on URL:"
r := regexp.MustCompile(fmt.Sprintf("(?m:%s)", expectedErrMsg))
if !r.MatchString(err.Error()) {
t.Fatalf("Error not matched: %s", err)
t.Fatalf("Want: %s\nGot: %s", expectedErrMsg, err.Error())
}
}
8 changes: 5 additions & 3 deletions proxy/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package proxy

import (
"fmt"
"net/http"
"regexp"

Expand Down Expand Up @@ -49,16 +50,17 @@ func Test_ListFunctions_Not200(t *testing.T) {
}
}

func Test_ListFunctions_BadURL(t *testing.T) {
func Test_ListFunctions_MissingURLPrefix(t *testing.T) {
_, err := ListFunctions("127.0.0.1:8080")

if err == nil {
t.Fatalf("Error was not returned")
}

r := regexp.MustCompile(`(?m:cannot connect to OpenFaaS on URL: )`)
expectedErrMsg := "cannot connect to OpenFaaS on URL:"
r := regexp.MustCompile(fmt.Sprintf("(?m:%s)", expectedErrMsg))
if !r.MatchString(err.Error()) {
t.Fatalf("Error not matched: %s", err)
t.Fatalf("Want: %s\nGot: %s", expectedErrMsg, err.Error())
}
}

Expand Down

0 comments on commit b606487

Please sign in to comment.