diff --git a/pkg/commands/compute/testdata/init/fastly-viceroy-update.toml b/pkg/commands/compute/testdata/init/fastly-viceroy-update.toml index 616395b47..9cb3214cf 100644 --- a/pkg/commands/compute/testdata/init/fastly-viceroy-update.toml +++ b/pkg/commands/compute/testdata/init/fastly-viceroy-update.toml @@ -34,3 +34,14 @@ name = "Default Rust template" foo = "bar" baz = """ qux""" + + [local_server.object_store] + store_one = [{key = "first", data = "This is some data"}, {key = "second", path = "strings.json"}] + + [[local_server.object_store.store_two]] + key = "first" + data = "This is some data" + + [[local_server.object_store.store_two]] + key = "second" + path = "strings.json" diff --git a/pkg/manifest/manifest.go b/pkg/manifest/manifest.go index a504ba812..b9ff6ce3c 100644 --- a/pkg/manifest/manifest.go +++ b/pkg/manifest/manifest.go @@ -249,9 +249,9 @@ type SetupLogger struct { // LocalServer represents a list of mocked Viceroy resources. type LocalServer struct { - Backends map[string]LocalBackend `toml:"backends"` - Dictionaries map[string]LocalDictionary `toml:"dictionaries,omitempty"` - ObjectStore map[string]LocalObjectStore `toml:"object_stores,omitempty"` + Backends map[string]LocalBackend `toml:"backends"` + Dictionaries map[string]LocalDictionary `toml:"dictionaries,omitempty"` + ObjectStore map[string][]LocalObjectStore `toml:"object_store,omitempty"` } // LocalBackend represents a backend to be mocked by the local testing server. @@ -272,8 +272,8 @@ type LocalDictionary struct { // LocalObjectStore represents an object_store to be mocked by the local testing server. type LocalObjectStore struct { Key string `toml:"key"` - Path string `toml:"path"` - Data string `toml:"data"` + Path string `toml:"path,omitempty"` + Data string `toml:"data,omitempty"` } // Exists yields whether the manifest exists. @@ -307,6 +307,12 @@ func (f *File) SetOutput(output io.Writer) { f.output = output } +func (f *File) logErr(err error) { + if f.errLog != nil { + f.errLog.Add(err) + } +} + // AutoMigrateVersion updates the manifest_version value to // ManifestLatestVersion if the current version is less than the latest // supported and only if there is no [setup] configuration defined. @@ -427,7 +433,7 @@ func (f *File) Read(path string) (err error) { /* #nosec */ data, err := os.ReadFile(path) if err != nil { - f.errLog.Add(err) + f.logErr(err) return err } @@ -442,14 +448,14 @@ func (f *File) Read(path string) (err error) { // structure otherwise we'll see errors from the toml library. manifestSection, err := containsManifestSection(data) if err != nil { - f.errLog.Add(err) + f.logErr(err) return fmt.Errorf("failed to parse the fastly.toml manifest: %w", err) } if manifestSection { buf, err := stripManifestSection(bytes.NewReader(data), path) if err != nil { - f.errLog.Add(err) + f.logErr(err) return fsterr.ErrInvalidManifestVersion } data = buf.Bytes() @@ -460,13 +466,13 @@ func (f *File) Read(path string) (err error) { // version supported by the Fastly CLI. data, err = f.AutoMigrateVersion(data, path) if err != nil { - f.errLog.Add(err) + f.logErr(err) return err } err = toml.Unmarshal(data, f) if err != nil { - f.errLog.Add(err) + f.logErr(err) return fsterr.ErrParsingManifest } @@ -481,7 +487,7 @@ func (f *File) Read(path string) (err error) { } err = f.Write(path) if err != nil { - f.errLog.Add(err) + f.logErr(err) return fmt.Errorf("unable to save fastly.toml manifest change: %w", err) } } diff --git a/pkg/manifest/manifest_test.go b/pkg/manifest/manifest_test.go index 65c1cde88..3a355cc63 100644 --- a/pkg/manifest/manifest_test.go +++ b/pkg/manifest/manifest_test.go @@ -12,6 +12,7 @@ import ( fsterr "github.com/fastly/cli/pkg/errors" "github.com/fastly/cli/pkg/manifest" "github.com/fastly/cli/pkg/testutil" + "github.com/google/go-cmp/cmp" toml "github.com/pelletier/go-toml" ) @@ -295,7 +296,8 @@ func TestManifestPersistsLocalServerSection(t *testing.T) { t.Fatal("expected [local_server] block to exist in fastly.toml but is missing") } - if lt.(*toml.Tree).String() != ot.(*toml.Tree).String() { - t.Fatal("testing section between original and updated fastly.toml do not match") + got, want := lt.(*toml.Tree).String(), ot.(*toml.Tree).String() + if diff := cmp.Diff(want, got); diff != "" { + t.Fatalf("testing section between original and updated fastly.toml do not match (-want +got):\n%s", diff) } } diff --git a/pkg/manifest/testdata/fastly-viceroy-update.toml b/pkg/manifest/testdata/fastly-viceroy-update.toml index 616395b47..9cb3214cf 100644 --- a/pkg/manifest/testdata/fastly-viceroy-update.toml +++ b/pkg/manifest/testdata/fastly-viceroy-update.toml @@ -34,3 +34,14 @@ name = "Default Rust template" foo = "bar" baz = """ qux""" + + [local_server.object_store] + store_one = [{key = "first", data = "This is some data"}, {key = "second", path = "strings.json"}] + + [[local_server.object_store.store_two]] + key = "first" + data = "This is some data" + + [[local_server.object_store.store_two]] + key = "second" + path = "strings.json"