Skip to content

Commit

Permalink
feat(nav): implement advanced config (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jan 3, 2024
1 parent 3688f00 commit 19533d0
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 86 deletions.
3 changes: 3 additions & 0 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Bootstrap struct {
ProfilesCFG proxy.ProfilesConfig
SchemesCFG proxy.SchemesConfig
SamplerCFG proxy.SamplerConfig
AdvancedCFG proxy.AdvancedConfig
Vfs storage.VirtualFS
}

Expand Down Expand Up @@ -101,6 +102,7 @@ func (b *Bootstrap) Root(options ...ConfigureOptionFn) *cobra.Command {
Profiles: &MsProfilesConfigReader{},
Schemes: &MsSchemesConfigReader{},
Sampler: &MsSamplerConfigReader{},
Advanced: &MsAdvancedConfigReader{},
},
},
}
Expand Down Expand Up @@ -237,4 +239,5 @@ func (b *Bootstrap) viper() {
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)
b.AdvancedCFG, _ = b.OptionsInfo.Config.Readers.Advanced.Read(b.OptionsInfo.Viper)
}
56 changes: 45 additions & 11 deletions src/app/command/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ 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/extendio/xfs/storage"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/mocks"
"github.com/snivilised/pixa/src/internal/helpers"
"github.com/snivilised/pixa/src/internal/matchers"
"go.uber.org/mock/gomock"
"golang.org/x/text/language"
)

Expand Down Expand Up @@ -38,27 +41,50 @@ func (j *DetectorStub) Scan() language.Tag {
var _ = Describe("Bootstrap", Ordered, func() {

var (
repo string
l10nPath string
configPath string
nfs storage.VirtualFS
repo string
l10nPath string
configPath string
config configuration.ViperConfig
vfs storage.VirtualFS
ctrl *gomock.Controller
mockProfilesReader *mocks.MockProfilesConfigReader
mockSchemesReader *mocks.MockSchemesConfigReader
mockSamplerReader *mocks.MockSamplerConfigReader
mockAdvancedReader *mocks.MockAdvancedConfigReader
mockViperConfig *cmocks.MockViperConfig
)

BeforeAll(func() {
nfs = storage.UseNativeFS()
repo = helpers.Repo(filepath.Join("..", "..", ".."))
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
vfs, _, config = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)

l10nPath = helpers.Path(repo, filepath.Join("test", "data", "l10n"))
Expect(matchers.AsDirectory(l10nPath)).To(matchers.ExistInFS(nfs))
ctrl = gomock.NewController(GinkgoT())
mockViperConfig = cmocks.NewMockViperConfig(ctrl)
mockProfilesReader = mocks.NewMockProfilesConfigReader(ctrl)
mockSchemesReader = mocks.NewMockSchemesConfigReader(ctrl)
mockSamplerReader = mocks.NewMockSamplerConfigReader(ctrl)
mockAdvancedReader = mocks.NewMockAdvancedConfigReader(ctrl)
helpers.DoMockReadInConfig(mockViperConfig)
helpers.DoMockConfigs(config,
mockProfilesReader, mockSchemesReader, mockSamplerReader, mockAdvancedReader,
)
})

configPath = filepath.Join(repo, "test", "data", "configuration")
Expect(matchers.AsDirectory(configPath)).To(matchers.ExistInFS(nfs))
AfterEach(func() {
ctrl.Finish()
})

Context("given: root defined with magick sub-command", func() {
It("🧪 should: setup command without error", func() {
bootstrap := command.Bootstrap{
Vfs: nfs,
Vfs: vfs,
}
rootCmd := bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
Expand All @@ -67,7 +93,15 @@ var _ = Describe("Bootstrap", Ordered, func() {
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Viper = &configuration.GlobalViperConfig{}
co.Config.Readers = command.ConfigReaders{
Profiles: mockProfilesReader,
Schemes: mockSchemesReader,
Sampler: mockSamplerReader,
Advanced: mockAdvancedReader,
}
})

Expect(rootCmd).NotTo(BeNil())
})
})
Expand Down
13 changes: 13 additions & 0 deletions src/app/command/config-readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ func (r *MsSamplerConfigReader) Read(viper configuration.ViperConfig) (proxy.Sam
return &samplerCFG, err
}

type MsAdvancedConfigReader struct{}

func (r *MsAdvancedConfigReader) Read(viper configuration.ViperConfig) (proxy.AdvancedConfig, error) {
var (
advancedCFG proxy.MsAdvancedConfig
)

err := viper.UnmarshalKey("advanced", &advancedCFG)

return &advancedCFG, err
}

type ConfigReaders struct {
Profiles proxy.ProfilesConfigReader
Schemes proxy.SchemesConfigReader
Sampler proxy.SamplerConfigReader
Advanced proxy.AdvancedConfigReader
}
59 changes: 50 additions & 9 deletions src/app/command/magick-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,86 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"

"github.com/snivilised/cobrass/src/assistant/configuration"
cmocks "github.com/snivilised/cobrass/src/assistant/mocks"
xi18n "github.com/snivilised/extendio/i18n"
"github.com/snivilised/extendio/xfs/storage"
"github.com/snivilised/pixa/src/app/command"
"github.com/snivilised/pixa/src/app/mocks"
"github.com/snivilised/pixa/src/internal/helpers"
"github.com/snivilised/pixa/src/internal/matchers"
)

var _ = Describe("MagickCmd", Ordered, func() {
var (
repo string
l10nPath string
nfs storage.VirtualFS
repo string
l10nPath string
configPath string
// root string
config configuration.ViperConfig
vfs storage.VirtualFS
ctrl *gomock.Controller
mockProfilesReader *mocks.MockProfilesConfigReader
mockSchemesReader *mocks.MockSchemesConfigReader
mockSamplerReader *mocks.MockSamplerConfigReader
mockAdvancedReader *mocks.MockAdvancedConfigReader
mockViperConfig *cmocks.MockViperConfig
)

BeforeAll(func() {
nfs = storage.UseNativeFS()
vfs = storage.UseNativeFS()
repo = helpers.Repo(filepath.Join("..", "..", ".."))
l10nPath = helpers.Path(repo, filepath.Join("test", "data", "l10n"))
Expect(matchers.AsDirectory(l10nPath)).To(matchers.ExistInFS(nfs))
Expect(matchers.AsDirectory(l10nPath)).To(matchers.ExistInFS(vfs))
})

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})

BeforeEach(func() {
xi18n.ResetTx()
vfs, _, config = helpers.SetupTest(
"nasa-scientist-index.xml", configPath, l10nPath, helpers.Silent,
)

if err := helpers.UseI18n(l10nPath); err != nil {
Fail(err.Error())
}
ctrl = gomock.NewController(GinkgoT())
mockViperConfig = cmocks.NewMockViperConfig(ctrl)
mockProfilesReader = mocks.NewMockProfilesConfigReader(ctrl)
mockSchemesReader = mocks.NewMockSchemesConfigReader(ctrl)
mockSamplerReader = mocks.NewMockSamplerConfigReader(ctrl)
mockAdvancedReader = mocks.NewMockAdvancedConfigReader(ctrl)
helpers.DoMockReadInConfig(mockViperConfig)
helpers.DoMockConfigs(config,
mockProfilesReader, mockSchemesReader, mockSamplerReader, mockAdvancedReader,
)
})

When("specified flags are valid", func() {
It("🧪 should: execute without error", func() {
bootstrap := command.Bootstrap{
Vfs: nfs,
Vfs: vfs,
}
tester := helpers.CommandTester{
Args: []string{"mag"},
Root: bootstrap.Root(func(co *command.ConfigureOptionsInfo) {
co.Detector = &DetectorStub{}
co.Program = &helpers.ExecutorStub{
Name: helpers.ProgName,
}
co.Config.Name = helpers.PixaConfigTestFilename
co.Config.ConfigPath = configPath
co.Viper = &configuration.GlobalViperConfig{}
co.Config.Readers = command.ConfigReaders{
Profiles: mockProfilesReader,
Schemes: mockSchemesReader,
Sampler: mockSamplerReader,
Advanced: mockAdvancedReader,
}
}),
}
_, err := tester.Execute()
Expand Down
1 change: 1 addition & 0 deletions src/app/command/shrink-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (b *Bootstrap) buildShrinkCommand(container *assistant.CobraContainer) *cob
b.ProfilesCFG,
b.SchemesCFG,
b.SamplerCFG,
b.AdvancedCFG,
b.Vfs,
)
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root
mockProfilesReader = mocks.NewMockProfilesConfigReader(ctrl)
mockSchemesReader = mocks.NewMockSchemesConfigReader(ctrl)
mockSamplerReader = mocks.NewMockSamplerConfigReader(ctrl)
mockAdvancedReader = mocks.NewMockAdvancedConfigReader(ctrl)
)

helpers.DoMockReadInConfig(mockViperConfig)
helpers.DoMockConfigs(config, mockProfilesReader, mockSchemesReader, mockSamplerReader)
helpers.DoMockConfigs(config,
mockProfilesReader, mockSchemesReader, mockSamplerReader, mockAdvancedReader,
)

tester := helpers.CommandTester{
Args: append(args, entry.args...),
Expand All @@ -83,6 +86,7 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *shrinkTE, root
Profiles: mockProfilesReader,
Schemes: mockSchemesReader,
Sampler: mockSamplerReader,
Advanced: mockAdvancedReader,
}
}),
}
Expand Down
Loading

0 comments on commit 19533d0

Please sign in to comment.