diff --git a/proxy/delete_test.go b/proxy/delete_test.go index a88fc1cd3..bd7ef8a34 100644 --- a/proxy/delete_test.go +++ b/proxy/delete_test.go @@ -4,6 +4,7 @@ package proxy import ( + "fmt" "net/http" "testing" @@ -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) } } diff --git a/proxy/deploy_test.go b/proxy/deploy_test.go index 62b135841..d6e6d3446 100644 --- a/proxy/deploy_test.go +++ b/proxy/deploy_test.go @@ -4,6 +4,7 @@ package proxy import ( + "fmt" "net/http" "testing" @@ -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() { @@ -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) } } diff --git a/proxy/invoke_test.go b/proxy/invoke_test.go index b76be1865..211e75029 100644 --- a/proxy/invoke_test.go +++ b/proxy/invoke_test.go @@ -4,6 +4,7 @@ package proxy import ( + "fmt" "net/http" "testing" @@ -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( @@ -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()) } } diff --git a/proxy/list_test.go b/proxy/list_test.go index bb3907b4e..5405d0a3e 100644 --- a/proxy/list_test.go +++ b/proxy/list_test.go @@ -4,6 +4,7 @@ package proxy import ( + "fmt" "net/http" "regexp" @@ -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()) } }