From 9b7271fcfc80c417a7cb6652d5b14e24a2846718 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Wed, 20 Sep 2023 22:42:58 -0300 Subject: [PATCH 1/3] Windows API doesn't like JSON with top-level array winrt::Windows::Data::Json::Json::TryParse failed with top-level array. It has to be a top-level object to make it happy. --- mocks/storeserver/storemockserver/storemockserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mocks/storeserver/storemockserver/storemockserver.go b/mocks/storeserver/storemockserver/storemockserver.go index 0c9a4a35c..c22b35b88 100644 --- a/mocks/storeserver/storemockserver/storemockserver.go +++ b/mocks/storeserver/storemockserver/storemockserver.go @@ -226,7 +226,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) { From d341ed2f2d426faacb7acc302e819601630fc7c8 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Thu, 21 Sep 2023 22:31:35 -0300 Subject: [PATCH 2/3] fix unmarshalling the settings should go to its own PR --- .../contractsmockserver/contractsmockserver.go | 6 ++++++ mocks/restserver/application.go | 6 ++++-- mocks/storeserver/storemockserver/storemockserver.go | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mocks/contractserver/contractsmockserver/contractsmockserver.go b/mocks/contractserver/contractsmockserver/contractsmockserver.go index f6f875360..4883f4642 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, unmarsheller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarsheller(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..7f41b4bca 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, unmarsheller 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 c22b35b88..b8d7b44a5 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, unmarsheller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarsheller(in, &s) + return s, err +} + // Server is a configurable mock of the MS Store runtime component that talks REST. type Server struct { restserver.ServerBase From be2675551b79f8e3d36ebc8a5e3d65dab10b6ee6 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Fri, 22 Sep 2023 03:51:47 -0300 Subject: [PATCH 3/3] FIx typo s/unmarsheller/unmarshaller/g --- .../contractserver/contractsmockserver/contractsmockserver.go | 4 ++-- mocks/restserver/application.go | 2 +- mocks/storeserver/storemockserver/storemockserver.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mocks/contractserver/contractsmockserver/contractsmockserver.go b/mocks/contractserver/contractsmockserver/contractsmockserver.go index 4883f4642..a717f6060 100644 --- a/mocks/contractserver/contractsmockserver/contractsmockserver.go +++ b/mocks/contractserver/contractsmockserver/contractsmockserver.go @@ -34,8 +34,8 @@ type Settings struct { } // Unmarshal tricks the type system so marshalling YAML will just work when called from the restserver.Settings interface. -func (s Settings) Unmarshal(in []byte, unmarsheller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { - err := unmarsheller(in, &s) +func (s Settings) Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarshaller(in, &s) return s, err } diff --git a/mocks/restserver/application.go b/mocks/restserver/application.go index 7f41b4bca..e3a72d650 100644 --- a/mocks/restserver/application.go +++ b/mocks/restserver/application.go @@ -24,7 +24,7 @@ type Server interface { // Settings is the minimal interface a settings backend must provide to the Application. type Settings interface { - Unmarshal(in []byte, unmarsheller func(in []byte, out interface{}) (err error)) (Settings, error) + Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (Settings, error) } // App encapsulates creating and managing the CLI and lifecycle. diff --git a/mocks/storeserver/storemockserver/storemockserver.go b/mocks/storeserver/storemockserver/storemockserver.go index b8d7b44a5..247d18b1a 100644 --- a/mocks/storeserver/storemockserver/storemockserver.go +++ b/mocks/storeserver/storemockserver/storemockserver.go @@ -98,8 +98,8 @@ type Settings struct { } // Unmarshal tricks the type system so marshalling YAML will just work when called from the restserver.Settings interface. -func (s Settings) Unmarshal(in []byte, unmarsheller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { - err := unmarsheller(in, &s) +func (s Settings) Unmarshal(in []byte, unmarshaller func(in []byte, out interface{}) (err error)) (restserver.Settings, error) { + err := unmarshaller(in, &s) return s, err }