From 2be9db699627e2a37c391bca04f7d55bdc524ba2 Mon Sep 17 00:00:00 2001 From: Brandur Date: Fri, 1 Sep 2017 10:54:00 -0700 Subject: [PATCH] Print warning when no fixture was found 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. --- generator.go | 2 ++ util/util.go | 11 +++++++++++ util/util_test.go | 1 + 3 files changed, 14 insertions(+) create mode 100644 util/util.go create mode 100644 util/util_test.go diff --git a/generator.go b/generator.go index 6ebf7799..0db1e5a7 100644 --- a/generator.go +++ b/generator.go @@ -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") @@ -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 } diff --git a/util/util.go b/util/util.go new file mode 100644 index 00000000..c92c0b44 --- /dev/null +++ b/util/util.go @@ -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...) +} diff --git a/util/util_test.go b/util/util_test.go new file mode 100644 index 00000000..c7d86821 --- /dev/null +++ b/util/util_test.go @@ -0,0 +1 @@ +package util