Skip to content

Commit

Permalink
feat(nav): implement schemes reader (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jan 3, 2024
1 parent 906001a commit 3688f00
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 103 deletions.
6 changes: 0 additions & 6 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ tasks:
cmds:
- goveralls -repotoken {{.COVERALLS_TOKEN}}

# === go generate ==========================================

co-gen-cfg:
cmds:
- go generate src/app/proxy

# === i18n =================================================

clear:
Expand Down
5 changes: 4 additions & 1 deletion src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Bootstrap struct {
Container *assistant.CobraContainer
OptionsInfo ConfigureOptionsInfo
ProfilesCFG proxy.ProfilesConfig
SchemesCFG proxy.SchemesConfig
SamplerCFG proxy.SamplerConfig
Vfs storage.VirtualFS
}
Expand Down Expand Up @@ -98,6 +99,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
Viper: &configuration.GlobalViperConfig{},
Readers: ConfigReaders{
Profiles: &MsProfilesConfigReader{},
Schemes: &MsSchemesConfigReader{},
Sampler: &MsSamplerConfigReader{},
},
},
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions src/app/command/config-readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
1 change: 1 addition & 0 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
40 changes: 32 additions & 8 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
}
Expand All @@ -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) {
Expand All @@ -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,
}
}),
}

Expand All @@ -77,6 +100,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
configPath string
root string
vfs storage.VirtualFS
config configuration.ViperConfig
)

BeforeAll(func() {
Expand All @@ -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,
)
})
Expand All @@ -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)
Expand Down Expand Up @@ -232,7 +256,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
expectValidShrinkCmdInvocation(vfs, entry, root, config)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -247,7 +271,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
expectValidShrinkCmdInvocation(vfs, entry, root, config)
})
})

Expand All @@ -264,7 +288,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
expectValidShrinkCmdInvocation(vfs, entry, root, config)
})

It("🧪 should: execute successfully", func() {
Expand All @@ -279,7 +303,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
},
}

expectValidShrinkCmdInvocation(vfs, entry, root)
expectValidShrinkCmdInvocation(vfs, entry, root, config)
})
})
})
123 changes: 92 additions & 31 deletions src/app/mocks/mocks-config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions src/app/proxy/config-defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
var (
DefaultProfilesConfig *MsProfilesConfig
DefaultSamplerConfig *MsSamplerConfig
DefaultSchemesConfig *MsSchemesConfig
)

func init() {
Expand Down Expand Up @@ -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"},
},
},
}
}
Loading

0 comments on commit 3688f00

Please sign in to comment.