Skip to content

Commit

Permalink
Print warning when no fixture was found
Browse files Browse the repository at this point in the history
Prints a warning to `stderr` when a fixture couldn't be found for a
resource ID as this is likely going to lead to problems.
  • Loading branch information
brandur committed Sep 1, 2017
1 parent 6f55235 commit 2be9db6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/stripe/stripe-mock/spec"
"github.com/stripe/stripe-mock/util"
)

var errExpansionNotSupported = fmt.Errorf("Expansion not supported")
Expand Down Expand Up @@ -111,6 +112,7 @@ func (g *DataGenerator) generateResource(schema *spec.JSONSchema) (interface{},

fixture, ok := g.fixtures.Resources[spec.ResourceID(schema.XResourceID)]
if !ok {
util.Warningf("No fixture for: %s", spec.ResourceID(schema.XResourceID))
return map[string]interface{}{}, nil
}

Expand Down
11 changes: 11 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package util

import (
"fmt"
"os"
)

func Warningf(format string, a ...interface{}) {
format = "WARNING: " + format + "\n"
fmt.Fprintf(os.Stderr, format, a...)
}
1 change: 1 addition & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package util

0 comments on commit 2be9db6

Please sign in to comment.