diff --git a/mocks/contractserver/contractsmockserver/contractsmockserver.go b/mocks/contractserver/contractsmockserver/contractsmockserver.go index f6f875360..a717f6060 100644 --- a/mocks/contractserver/contractsmockserver/contractsmockserver.go +++ b/mocks/contractserver/contractsmockserver/contractsmockserver.go @@ -33,6 +33,12 @@ type Settings struct { Subscription restserver.Endpoint } +// Unmarshal tricks the type system so marshalling YAML will just work when called from the restserver.Settings interface. +func (s Settings) Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarshaller(in, &s) + return s, err +} + // DefaultSettings returns the default set of settings for the server. func DefaultSettings() Settings { return Settings{ diff --git a/mocks/restserver/application.go b/mocks/restserver/application.go index 7c11ceabb..e3a72d650 100644 --- a/mocks/restserver/application.go +++ b/mocks/restserver/application.go @@ -23,7 +23,9 @@ type Server interface { } // Settings is the minimal interface a settings backend must provide to the Application. -type Settings interface{} +type Settings interface { + Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (Settings, error) +} // App encapsulates creating and managing the CLI and lifecycle. type App struct { @@ -143,7 +145,7 @@ The outfile, if provided, will contain the address.`, app.Description), os.Exit(1) } - if err := yaml.Unmarshal(out, &settings); err != nil { + if settings, err = settings.Unmarshal(out, yaml.Unmarshal); err != nil { slog.Error(fmt.Sprintf("Could not unmarshal settings: %v", err)) os.Exit(1) } diff --git a/mocks/storeserver/storemockserver/storemockserver.go b/mocks/storeserver/storemockserver/storemockserver.go index 0c9a4a35c..247d18b1a 100644 --- a/mocks/storeserver/storemockserver/storemockserver.go +++ b/mocks/storeserver/storemockserver/storemockserver.go @@ -97,6 +97,12 @@ type Settings struct { AllProducts []Product } +// Unmarshal tricks the type system so marshalling YAML will just work when called from the restserver.Settings interface. +func (s Settings) Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarshaller(in, &s) + return s, err +} + // Server is a configurable mock of the MS Store runtime component that talks REST. type Server struct { restserver.ServerBase @@ -226,7 +232,7 @@ func (s *Server) handleGetProducts(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprint(w, string(bs)) + fmt.Fprintf(w, `{%q:%s}`, "products", string(bs)) } func (s *Server) handlePurchase(w http.ResponseWriter, r *http.Request) {