Skip to content

Commit

Permalink
Fix broken unit test in 404 use-case
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 7, 2022
1 parent 670e9c7 commit fa46e5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion types/function_list_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (s *FunctionLookupBuilder) getNamespaces() ([]string, error) {
if res.Body != nil {
defer res.Body.Close()
}

bytesOut, err := ioutil.ReadAll(res.Body)
if err != nil {
return namespaces, err
Expand All @@ -94,7 +95,7 @@ func (s *FunctionLookupBuilder) getNamespaces() ([]string, error) {
}

if err := json.Unmarshal(bytesOut, &namespaces); err != nil {
return namespaces, err
return namespaces, fmt.Errorf("unable to marshal to JSON: %s, error: %w", string(bytesOut), err)
}

return namespaces, err
Expand Down
16 changes: 9 additions & 7 deletions types/function_list_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package types

import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/openfaas/faas-provider/types"
Expand Down Expand Up @@ -404,14 +406,14 @@ func Test_GetNamespaces_ProviderGives404(t *testing.T) {
GatewayURL: srv.URL,
}

namespaces, err := builder.getNamespaces()
if err != nil {
t.Errorf("%s", err.Error())
_, err := builder.getNamespaces()
if err == nil {
t.Fatalf("expected error, but got none")
}
want := 0
got := len(namespaces)
if len(namespaces) != 0 {
t.Errorf("Namespaces when 404, want %d, but got: %d", want, got)

wantStr := "unable to marshal to JSON"
if strings.Contains(err.Error(), wantStr) == false {
fmt.Errorf("want error to contain %s, but got %s", wantStr, err.Error())
}
}

Expand Down

0 comments on commit fa46e5a

Please sign in to comment.