From 3688f000467195c0ac2284736743cae901b3ef94 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Wed, 3 Jan 2024 16:23:22 +0000 Subject: [PATCH] feat(nav): implement schemes reader (#92) --- Taskfile.yml | 6 - src/app/command/bootstrap.go | 5 +- src/app/command/config-readers.go | 13 ++ src/app/command/shrink-cmd.go | 1 + src/app/command/shrink-cmd_test.go | 40 ++++-- src/app/mocks/mocks-config.go | 123 +++++++++++++----- src/app/proxy/config-defaults.go | 24 ++-- .../proxy/{sampler-config.go => config.go} | 32 +++-- src/app/proxy/controller-sampler_test.go | 7 +- src/app/proxy/controller.go | 8 +- src/app/proxy/enter-shrink.go | 5 +- src/app/proxy/entry-base.go | 1 + src/app/proxy/execution-step.go | 6 +- src/app/proxy/proxy-defs.go | 1 + src/internal/helpers/mock-config-data.go | 30 +++-- src/internal/helpers/test-utils.go | 18 ++- test/data/configuration/pixa-test.yml | 16 +-- 17 files changed, 233 insertions(+), 103 deletions(-) rename src/app/proxy/{sampler-config.go => config.go} (71%) diff --git a/Taskfile.yml b/Taskfile.yml index 3ee07c2..6bbcec0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -206,12 +206,6 @@ tasks: cmds: - goveralls -repotoken {{.COVERALLS_TOKEN}} - # === go generate ========================================== - - co-gen-cfg: - cmds: - - go generate src/app/proxy - # === i18n ================================================= clear: diff --git a/src/app/command/bootstrap.go b/src/app/command/bootstrap.go index 6a9bf0f..8194bb2 100644 --- a/src/app/command/bootstrap.go +++ b/src/app/command/bootstrap.go @@ -67,6 +67,7 @@ type Bootstrap struct { Container *assistant.CobraContainer OptionsInfo ConfigureOptionsInfo ProfilesCFG proxy.ProfilesConfig + SchemesCFG proxy.SchemesConfig SamplerCFG proxy.SamplerConfig Vfs storage.VirtualFS } @@ -98,6 +99,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command { Viper: &configuration.GlobalViperConfig{}, Readers: ConfigReaders{ Profiles: &MsProfilesConfigReader{}, + Schemes: &MsSchemesConfigReader{}, Sampler: &MsSamplerConfigReader{}, }, }, @@ -148,7 +150,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command { } if scheme := inputs.ProfileFam.Native.Scheme; scheme != "" { - if err := b.SamplerCFG.Validate(scheme, b.ProfilesCFG); err != nil { + if err := b.SchemesCFG.Validate(scheme, b.ProfilesCFG); err != nil { return err } } @@ -233,5 +235,6 @@ func (b *Bootstrap) viper() { // TODO: handle the read errors // b.ProfilesCFG, _ = b.OptionsInfo.Config.Readers.Profiles.Read(b.OptionsInfo.Config.Viper) + b.SchemesCFG, _ = b.OptionsInfo.Config.Readers.Schemes.Read(b.OptionsInfo.Config.Viper) b.SamplerCFG, _ = b.OptionsInfo.Config.Readers.Sampler.Read(b.OptionsInfo.Config.Viper) } diff --git a/src/app/command/config-readers.go b/src/app/command/config-readers.go index 1df1682..9d3b240 100644 --- a/src/app/command/config-readers.go +++ b/src/app/command/config-readers.go @@ -39,6 +39,18 @@ func (r *MsProfilesConfigReader) Read(viper configuration.ViperConfig) (proxy.Pr return profilesCFG, nil } +type MsSchemesConfigReader struct{} + +func (r *MsSchemesConfigReader) Read(viper configuration.ViperConfig) (proxy.SchemesConfig, error) { + var ( + schemesCFG proxy.MsSchemesConfig + ) + + err := viper.UnmarshalKey("schemes", &schemesCFG) + + return schemesCFG, err +} + type MsSamplerConfigReader struct{} func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (proxy.SamplerConfig, error) { @@ -53,5 +65,6 @@ func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (proxy.Sam type ConfigReaders struct { Profiles proxy.ProfilesConfigReader + Schemes proxy.SchemesConfigReader Sampler proxy.SamplerConfigReader } diff --git a/src/app/command/shrink-cmd.go b/src/app/command/shrink-cmd.go index c18fe63..aba56d1 100644 --- a/src/app/command/shrink-cmd.go +++ b/src/app/command/shrink-cmd.go @@ -137,6 +137,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob b.OptionsInfo.Program, b.OptionsInfo.Config.Viper, b.ProfilesCFG, + b.SchemesCFG, b.SamplerCFG, b.Vfs, ) diff --git a/src/app/command/shrink-cmd_test.go b/src/app/command/shrink-cmd_test.go index 875175a..21c9d77 100644 --- a/src/app/command/shrink-cmd_test.go +++ b/src/app/command/shrink-cmd_test.go @@ -6,9 +6,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - + "github.com/snivilised/cobrass/src/assistant/configuration" + cmocks "github.com/snivilised/cobrass/src/assistant/mocks" "github.com/snivilised/pixa/src/app/command" + "github.com/snivilised/pixa/src/app/mocks" "github.com/snivilised/pixa/src/internal/helpers" + "go.uber.org/mock/gomock" "github.com/snivilised/extendio/xfs/storage" ) @@ -32,7 +35,9 @@ type shrinkTE struct { directory string } -func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string) { +func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root string, + config configuration.ViperConfig, +) { bootstrap := command.Bootstrap{ Vfs: vfs, } @@ -52,6 +57,17 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root args = append(args, entry.trashFlag, trash) } + var ( + ctrl = gomock.NewController(GinkgoT()) + mockViperConfig = cmocks.NewMockViperConfig(ctrl) + mockProfilesReader = mocks.NewMockProfilesConfigReader(ctrl) + mockSchemesReader = mocks.NewMockSchemesConfigReader(ctrl) + mockSamplerReader = mocks.NewMockSamplerConfigReader(ctrl) + ) + + helpers.DoMockReadInConfig(mockViperConfig) + helpers.DoMockConfigs(config, mockProfilesReader, mockSchemesReader, mockSamplerReader) + tester := helpers.CommandTester{ Args: append(args, entry.args...), Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) { @@ -61,6 +77,13 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root } co.Config.Name = helpers.PixaConfigTestFilename co.Config.ConfigPath = entry.configPath + + co.Viper = &configuration.GlobalViperConfig{} + co.Config.Readers = command.ConfigReaders{ + Profiles: mockProfilesReader, + Schemes: mockSchemesReader, + Sampler: mockSamplerReader, + } }), } @@ -77,6 +100,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { configPath string root string vfs storage.VirtualFS + config configuration.ViperConfig ) BeforeAll(func() { @@ -86,7 +110,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }) BeforeEach(func() { - vfs, root, _ = helpers.SetupTest( + vfs, root, config = helpers.SetupTest( "nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent, ) }) @@ -95,7 +119,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { func(entry *shrinkTE) { entry.directory = BackyardWorldsPlanet9Scan01 entry.configPath = configPath - expectValidShrinkCmdInvocation(vfs, entry, root) + expectValidShrinkCmdInvocation(vfs, entry, root, config) }, func(entry *shrinkTE) string { return fmt.Sprintf("🧪 ===> given: '%v'", entry.message) @@ -232,7 +256,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + expectValidShrinkCmdInvocation(vfs, entry, root, config) }) It("🧪 should: execute successfully", func() { @@ -247,7 +271,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + expectValidShrinkCmdInvocation(vfs, entry, root, config) }) }) @@ -264,7 +288,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + expectValidShrinkCmdInvocation(vfs, entry, root, config) }) It("🧪 should: execute successfully", func() { @@ -279,7 +303,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() { }, } - expectValidShrinkCmdInvocation(vfs, entry, root) + expectValidShrinkCmdInvocation(vfs, entry, root, config) }) }) }) diff --git a/src/app/mocks/mocks-config.go b/src/app/mocks/mocks-config.go index 3ece050..9a92c57 100644 --- a/src/app/mocks/mocks-config.go +++ b/src/app/mocks/mocks-config.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: src/app/proxy/sampler-config.go +// Source: sampler-config.go // // Generated by this command: // -// mockgen -destination src/app/mocks/mocks-config.go -package mocks -source src/app/proxy/sampler-config.go +// mockgen -destination ../mocks/mocks-config.go -package mocks -source sampler-config.go // // Package mocks is a generated GoMock package. package mocks @@ -93,6 +93,96 @@ func (mr *MockProfilesConfigReaderMockRecorder) Read(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockProfilesConfigReader)(nil).Read), arg0) } +// MockSchemesConfig is a mock of SchemesConfig interface. +type MockSchemesConfig struct { + ctrl *gomock.Controller + recorder *MockSchemesConfigMockRecorder +} + +// MockSchemesConfigMockRecorder is the mock recorder for MockSchemesConfig. +type MockSchemesConfigMockRecorder struct { + mock *MockSchemesConfig +} + +// NewMockSchemesConfig creates a new mock instance. +func NewMockSchemesConfig(ctrl *gomock.Controller) *MockSchemesConfig { + mock := &MockSchemesConfig{ctrl: ctrl} + mock.recorder = &MockSchemesConfigMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSchemesConfig) EXPECT() *MockSchemesConfigMockRecorder { + return m.recorder +} + +// Scheme mocks base method. +func (m *MockSchemesConfig) Scheme(name string) (proxy.MsSchemeConfig, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Scheme", name) + ret0, _ := ret[0].(proxy.MsSchemeConfig) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// Scheme indicates an expected call of Scheme. +func (mr *MockSchemesConfigMockRecorder) Scheme(name any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Scheme", reflect.TypeOf((*MockSchemesConfig)(nil).Scheme), name) +} + +// Validate mocks base method. +func (m *MockSchemesConfig) Validate(name string, profiles proxy.ProfilesConfig) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validate", name, profiles) + ret0, _ := ret[0].(error) + return ret0 +} + +// Validate indicates an expected call of Validate. +func (mr *MockSchemesConfigMockRecorder) Validate(name, profiles any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockSchemesConfig)(nil).Validate), name, profiles) +} + +// MockSchemesConfigReader is a mock of SchemesConfigReader interface. +type MockSchemesConfigReader struct { + ctrl *gomock.Controller + recorder *MockSchemesConfigReaderMockRecorder +} + +// MockSchemesConfigReaderMockRecorder is the mock recorder for MockSchemesConfigReader. +type MockSchemesConfigReaderMockRecorder struct { + mock *MockSchemesConfigReader +} + +// NewMockSchemesConfigReader creates a new mock instance. +func NewMockSchemesConfigReader(ctrl *gomock.Controller) *MockSchemesConfigReader { + mock := &MockSchemesConfigReader{ctrl: ctrl} + mock.recorder = &MockSchemesConfigReaderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSchemesConfigReader) EXPECT() *MockSchemesConfigReaderMockRecorder { + return m.recorder +} + +// Read mocks base method. +func (m *MockSchemesConfigReader) Read(arg0 configuration.ViperConfig) (proxy.SchemesConfig, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", arg0) + ret0, _ := ret[0].(proxy.SchemesConfig) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockSchemesConfigReaderMockRecorder) Read(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockSchemesConfigReader)(nil).Read), arg0) +} + // MockSamplerConfig is a mock of SamplerConfig interface. type MockSamplerConfig struct { ctrl *gomock.Controller @@ -144,35 +234,6 @@ func (mr *MockSamplerConfigMockRecorder) NoFolders() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NoFolders", reflect.TypeOf((*MockSamplerConfig)(nil).NoFolders)) } -// Scheme mocks base method. -func (m *MockSamplerConfig) Scheme(name string) (proxy.MsSchemeConfig, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Scheme", name) - ret0, _ := ret[0].(proxy.MsSchemeConfig) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// Scheme indicates an expected call of Scheme. -func (mr *MockSamplerConfigMockRecorder) Scheme(name any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Scheme", reflect.TypeOf((*MockSamplerConfig)(nil).Scheme), name) -} - -// Validate mocks base method. -func (m *MockSamplerConfig) Validate(name string, profiles proxy.ProfilesConfig) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Validate", name, profiles) - ret0, _ := ret[0].(error) - return ret0 -} - -// Validate indicates an expected call of Validate. -func (mr *MockSamplerConfigMockRecorder) Validate(name, profiles any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockSamplerConfig)(nil).Validate), name, profiles) -} - // MockSamplerConfigReader is a mock of SamplerConfigReader interface. type MockSamplerConfigReader struct { ctrl *gomock.Controller diff --git a/src/app/proxy/config-defaults.go b/src/app/proxy/config-defaults.go index f3fa79c..ee2953c 100644 --- a/src/app/proxy/config-defaults.go +++ b/src/app/proxy/config-defaults.go @@ -12,6 +12,7 @@ const ( var ( DefaultProfilesConfig *MsProfilesConfig DefaultSamplerConfig *MsSamplerConfig + DefaultSchemesConfig *MsSchemesConfig ) func init() { @@ -40,19 +41,20 @@ func init() { }, } + DefaultSchemesConfig = &MsSchemesConfig{ + "blur-sf": MsSchemeConfig{ + Profiles: []string{"blur", "sf"}, + }, + "adaptive-sf": MsSchemeConfig{ + Profiles: []string{"adaptive", "sf"}, + }, + "adaptive-blur": MsSchemeConfig{ + Profiles: []string{"adaptive", "blur"}, + }, + } + DefaultSamplerConfig = &MsSamplerConfig{ Files: defaultNoFiles, Folders: defaultNoFolders, - Schemes: MsSamplerSchemesConfig{ - "blur-sf": MsSchemeConfig{ - Profiles: []string{"blur", "sf"}, - }, - "adaptive-sf": MsSchemeConfig{ - Profiles: []string{"adaptive", "sf"}, - }, - "adaptive-blur": MsSchemeConfig{ - Profiles: []string{"adaptive", "blur"}, - }, - }, } } diff --git a/src/app/proxy/sampler-config.go b/src/app/proxy/config.go similarity index 71% rename from src/app/proxy/sampler-config.go rename to src/app/proxy/config.go index f98235d..ce5766c 100644 --- a/src/app/proxy/sampler-config.go +++ b/src/app/proxy/config.go @@ -7,14 +7,14 @@ import ( "github.com/snivilised/cobrass/src/clif" ) -//go:generate mockgen -destination src/app/mocks/mocks-config.go -package mocks -source src/app/proxy/sampler-config.go +//go:generate mockgen -destination ../mocks/mocks-config.go -package mocks -source sampler-config.go type ( MsSchemeConfig struct { Profiles []string `mapstructure:"profiles"` } - MsSamplerSchemesConfig map[string]MsSchemeConfig + MsSchemesConfig map[string]MsSchemeConfig ProfilesConfig interface { Profile(name string) (clif.ChangedFlagsMap, bool) @@ -24,9 +24,16 @@ type ( Read(configuration.ViperConfig) (ProfilesConfig, error) } - SamplerConfig interface { + SchemesConfig interface { Validate(name string, profiles ProfilesConfig) error Scheme(name string) (MsSchemeConfig, bool) + } + + SchemesConfigReader interface { + Read(configuration.ViperConfig) (SchemesConfig, error) + } + + SamplerConfig interface { NoFiles() uint NoFolders() uint } @@ -46,13 +53,7 @@ func (cfg MsProfilesConfig) Profile(name string) (clif.ChangedFlagsMap, bool) { return profile, found } -type MsSamplerConfig struct { - Files uint `mapstructure:"files"` - Folders uint `mapstructure:"folders"` - Schemes MsSamplerSchemesConfig `mapstructure:"schemes"` -} - -func (cfg *MsSamplerConfig) Validate(name string, profiles ProfilesConfig) error { +func (cfg MsSchemesConfig) Validate(name string, profiles ProfilesConfig) error { if name == "" { return nil } @@ -62,7 +63,7 @@ func (cfg *MsSamplerConfig) Validate(name string, profiles ProfilesConfig) error scheme MsSchemeConfig ) - if scheme, found = cfg.Schemes[name]; !found { + if scheme, found = cfg[name]; !found { return fmt.Errorf("scheme: '%v' not found in config", name) } @@ -77,12 +78,17 @@ func (cfg *MsSamplerConfig) Validate(name string, profiles ProfilesConfig) error return nil } -func (cfg *MsSamplerConfig) Scheme(name string) (MsSchemeConfig, bool) { - config, found := cfg.Schemes[name] +func (cfg MsSchemesConfig) Scheme(name string) (MsSchemeConfig, bool) { + config, found := cfg[name] return config, found } +type MsSamplerConfig struct { + Files uint `mapstructure:"files"` + Folders uint `mapstructure:"folders"` +} + func (cfg *MsSamplerConfig) NoFiles() uint { return cfg.Files } diff --git a/src/app/proxy/controller-sampler_test.go b/src/app/proxy/controller-sampler_test.go index c832eab..e57ed52 100644 --- a/src/app/proxy/controller-sampler_test.go +++ b/src/app/proxy/controller-sampler_test.go @@ -58,6 +58,7 @@ var _ = Describe("SamplerController", Ordered, func() { vfs storage.VirtualFS ctrl *gomock.Controller mockProfilesReader *mocks.MockProfilesConfigReader + mockSchemesReader *mocks.MockSchemesConfigReader mockSamplerReader *mocks.MockSamplerConfigReader mockViperConfig *cmocks.MockViperConfig ) @@ -76,8 +77,9 @@ var _ = Describe("SamplerController", Ordered, func() { ctrl = gomock.NewController(GinkgoT()) mockViperConfig = cmocks.NewMockViperConfig(ctrl) mockProfilesReader = mocks.NewMockProfilesConfigReader(ctrl) + mockSchemesReader = mocks.NewMockSchemesConfigReader(ctrl) mockSamplerReader = mocks.NewMockSamplerConfigReader(ctrl) - helpers.DoMockViper(mockViperConfig) + helpers.DoMockReadInConfig(mockViperConfig) }) AfterEach(func() { @@ -86,7 +88,7 @@ var _ = Describe("SamplerController", Ordered, func() { DescribeTable("sampler", func(entry *samplerTE) { - helpers.DoMockConfigs(config, mockProfilesReader, mockSamplerReader) + helpers.DoMockConfigs(config, mockProfilesReader, mockSchemesReader, mockSamplerReader) directory := helpers.Path(root, entry.relative) options := []string{ @@ -120,6 +122,7 @@ var _ = Describe("SamplerController", Ordered, func() { co.Viper = &configuration.GlobalViperConfig{} co.Config.Readers = command.ConfigReaders{ Profiles: mockProfilesReader, + Schemes: mockSchemesReader, Sampler: mockSamplerReader, } }), diff --git a/src/app/proxy/controller.go b/src/app/proxy/controller.go index e7cdd3b..7b8d71b 100644 --- a/src/app/proxy/controller.go +++ b/src/app/proxy/controller.go @@ -50,7 +50,7 @@ func (c *controller) profileSequence( ) Sequence { changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL cl := c.composeProfileCL(pi.profile, changed) - step := &magickStep{ + step := &executionStep{ shared: c.shared, thirdPartyCL: cl, sourcePath: pi.item.Path, @@ -66,12 +66,12 @@ func (c *controller) schemeSequence( pi *pathInfo, ) Sequence { changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL - schemeCfg, _ := c.shared.sampler.Scheme(pi.scheme) // scheme already validated + schemeCfg, _ := c.shared.schemes.Scheme(pi.scheme) // scheme already validated sequence := make(Sequence, 0, len(schemeCfg.Profiles)) for _, current := range schemeCfg.Profiles { cl := c.composeProfileCL(current, changed) - step := &magickStep{ + step := &executionStep{ shared: c.shared, thirdPartyCL: cl, sourcePath: pi.item.Path, @@ -90,7 +90,7 @@ func (c *controller) adhocSequence( pi *pathInfo, ) Sequence { changed := c.shared.Inputs.ParamSet.Native.ThirdPartySet.LongChangedCL - step := &magickStep{ + step := &executionStep{ shared: c.shared, thirdPartyCL: changed, sourcePath: pi.item.Path, diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index d602e01..f5c3deb 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -160,7 +160,7 @@ func (e *ShrinkEntry) createFinder() *PathFinder { } if finder.Scheme != "" { - schemeCFG, _ := e.SamplerCFG.Scheme(finder.Scheme) + schemeCFG, _ := e.SchemesCFG.Scheme(finder.Scheme) finder.arity = len(schemeCFG.Profiles) } @@ -200,6 +200,7 @@ func (e *ShrinkEntry) ConfigureOptions(o *nav.TraverseOptions) { Options: e.Options, program: e.Program, profiles: e.ProfilesCFG, + schemes: e.SchemesCFG, sampler: e.SamplerCFG, Inputs: e.Inputs, finder: finder, @@ -286,6 +287,7 @@ func EnterShrink( program Executor, config configuration.ViperConfig, profilesCFG ProfilesConfig, + schemesCFG SchemesConfig, samplerCFG SamplerConfig, vfs storage.VirtualFS, ) error { @@ -297,6 +299,7 @@ func EnterShrink( Program: program, Config: config, ProfilesCFG: profilesCFG, + SchemesCFG: schemesCFG, SamplerCFG: samplerCFG, Vfs: vfs, }, diff --git a/src/app/proxy/entry-base.go b/src/app/proxy/entry-base.go index 05b5e3c..a8ff4b4 100644 --- a/src/app/proxy/entry-base.go +++ b/src/app/proxy/entry-base.go @@ -42,6 +42,7 @@ type EntryBase struct { Options *nav.TraverseOptions Registry *ControllerRegistry ProfilesCFG ProfilesConfig + SchemesCFG SchemesConfig SamplerCFG SamplerConfig Vfs storage.VirtualFS FileManager *FileManager diff --git a/src/app/proxy/execution-step.go b/src/app/proxy/execution-step.go index 140a7b8..ba034d6 100644 --- a/src/app/proxy/execution-step.go +++ b/src/app/proxy/execution-step.go @@ -20,11 +20,11 @@ type ( Sequence []Step ) -// magickStep knows how to combine parameters together so that the program +// executionStep knows how to combine parameters together so that the program // can be invoked correctly; but it does not know how to compose the input // and output file names; this is the responsibility of the controller, which uses // the path-finder to accomplish that task. -type magickStep struct { +type executionStep struct { shared *SharedControllerInfo thirdPartyCL clif.ThirdPartyCommandLine profile string @@ -34,7 +34,7 @@ type magickStep struct { } // Run -func (s *magickStep) Run(pi *pathInfo) error { +func (s *executionStep) Run(pi *pathInfo) error { folder, file := s.shared.finder.Result(pi) result := filepath.Join(folder, file) input := []string{pi.runStep.Source} diff --git a/src/app/proxy/proxy-defs.go b/src/app/proxy/proxy-defs.go index 54317c3..d432839 100644 --- a/src/app/proxy/proxy-defs.go +++ b/src/app/proxy/proxy-defs.go @@ -8,6 +8,7 @@ type SharedControllerInfo struct { Options *nav.TraverseOptions program Executor profiles ProfilesConfig + schemes SchemesConfig sampler SamplerConfig Inputs *ShrinkCommandInputs finder *PathFinder diff --git a/src/internal/helpers/mock-config-data.go b/src/internal/helpers/mock-config-data.go index 35a9799..6a6a242 100644 --- a/src/internal/helpers/mock-config-data.go +++ b/src/internal/helpers/mock-config-data.go @@ -13,6 +13,7 @@ var ( BackyardWorldsPlanet9Scan01Last4 []string ProfilesConfigData proxy.ProfilesConfigMap + SchemesConfigData *proxy.MsSchemesConfig SamplerConfigData *proxy.MsSamplerConfig ) @@ -67,22 +68,23 @@ func init() { }, } + SchemesConfigData = &proxy.MsSchemesConfig{ + "blur-sf": proxy.MsSchemeConfig{ + Profiles: []string{"blur", "sf"}, + }, + "adaptive-sf": proxy.MsSchemeConfig{ + Profiles: []string{"adaptive", "sf"}, + }, + "adaptive-blur": proxy.MsSchemeConfig{ + Profiles: []string{"adaptive", "blur"}, + }, + "singleton": proxy.MsSchemeConfig{ + Profiles: []string{"adaptive"}, + }, + } + SamplerConfigData = &proxy.MsSamplerConfig{ Files: 2, //nolint:gomnd // not magic Folders: 1, - Schemes: proxy.MsSamplerSchemesConfig{ - "blur-sf": proxy.MsSchemeConfig{ - Profiles: []string{"blur", "sf"}, - }, - "adaptive-sf": proxy.MsSchemeConfig{ - Profiles: []string{"adaptive", "sf"}, - }, - "adaptive-blur": proxy.MsSchemeConfig{ - Profiles: []string{"adaptive", "blur"}, - }, - "singleton": proxy.MsSchemeConfig{ - Profiles: []string{"adaptive"}, - }, - }, } } diff --git a/src/internal/helpers/test-utils.go b/src/internal/helpers/test-utils.go index 3293243..2017a1e 100644 --- a/src/internal/helpers/test-utils.go +++ b/src/internal/helpers/test-utils.go @@ -169,13 +169,15 @@ func MockConfigFile(vfs storage.VirtualFS, configPath string) error { func DoMockConfigs( config configuration.ViperConfig, profilesReader *mocks.MockProfilesConfigReader, + schemesReader *mocks.MockSchemesConfigReader, samplerReader *mocks.MockSamplerConfigReader, ) { DoMockProfilesConfigsWith(ProfilesConfigData, config, profilesReader) + DoMockSchemesConfigWith(SchemesConfigData, config, schemesReader) DoMockSamplerConfigWith(SamplerConfigData, config, samplerReader) } -func DoMockViper(config *cmocks.MockViperConfig) { +func DoMockReadInConfig(config *cmocks.MockViperConfig) { config.EXPECT().ReadInConfig().DoAndReturn( func() error { return nil @@ -199,6 +201,20 @@ func DoMockProfilesConfigsWith( ).AnyTimes() } +func DoMockSchemesConfigWith( + data *proxy.MsSchemesConfig, + config configuration.ViperConfig, + reader *mocks.MockSchemesConfigReader, +) { + reader.EXPECT().Read(config).DoAndReturn( + func(viper configuration.ViperConfig) (proxy.SchemesConfig, error) { + stub := data + + return stub, nil + }, + ).AnyTimes() +} + func DoMockSamplerConfigWith( data *proxy.MsSamplerConfig, config configuration.ViperConfig, diff --git a/test/data/configuration/pixa-test.yml b/test/data/configuration/pixa-test.yml index 603d0e3..110eb9e 100644 --- a/test/data/configuration/pixa-test.yml +++ b/test/data/configuration/pixa-test.yml @@ -13,17 +13,17 @@ profiles: interlace: "plane" gaussian-blur: "0.25" adaptive-resize: "60" +schemes: + blur-sf: + profiles: ["blur", "sf"] + adaptive-sf: + profiles: ["adaptive", "sf"] + adaptive-blur: + profiles: ["adaptive", "blur"] + singleton: ["adaptive"] sampler: files: 2 folders: 1 - schemes: - blur-sf: - profiles: ["blur", "sf"] - adaptive-sf: - profiles: ["adaptive", "sf"] - adaptive-blur: - profiles: ["adaptive", "blur"] - singleton: ["adaptive"] advanced: abort-on-error: false external-program-execution-timeout: "20s"