Skip to content

Commit

Permalink
test(proxy): mock configs (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Dec 14, 2023
1 parent 4837a48 commit 1982265
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 467 deletions.
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ require (
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/avfs/avfs v0.33.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20231212022811-ec68065c825e // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/tools v0.16.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

require (
Expand All @@ -46,7 +41,7 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/nicksnyder/go-i18n/v2 v2.3.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/snivilised/cobrass v0.4.0
github.com/snivilised/cobrass v0.4.1
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5
Expand Down
457 changes: 7 additions & 450 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/app/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type ConfigInfo struct {
type Bootstrap struct {
Container *assistant.CobraContainer
optionsInfo ConfigureOptionsInfo
ProfilesCFG proxy.ProfilesConfig
ProfilesCFG proxy.ProfilesConfigL
SamplerCFG proxy.SamplerConfig
}

Expand Down Expand Up @@ -216,7 +216,7 @@ func handleLangSetting(config configuration.ViperConfig) {
}

func (b *Bootstrap) viper() {
b.ProfilesCFG = make(proxy.ProfilesConfig)
b.ProfilesCFG = make(proxy.ProfilesConfigL)

// Ideally, the ProfileParameterSet would perform a check against
// the config, but extendio is not aware of config, so it can't
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func EnterShrink(
inputs *ShrinkCommandInputs,
program Executor,
config configuration.ViperConfig,
profilesCFG ProfilesConfig,
profilesCFG ProfilesConfigL,
samplerCFG *SamplerConfig,
) error {
fmt.Printf("---> 🔊🔊 Directory: '%v'\n", inputs.Root.ParamSet.Native.Directory)
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/entry-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type EntryBase struct {
Config configuration.ViperConfig
Options *nav.TraverseOptions
Registry *RunnerRegistry
ProfilesCFG ProfilesConfig
ProfilesCFG ProfilesConfigL
SamplerCFG *SamplerConfig
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/proxy/image-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type RootParameterSet struct { // should contain RootCommandInputs

type (
ProfilesFlagOptionAsAnyPair = map[string]any
ProfilesFlagOptionPair = map[string]string
ProfilesConfig map[string]clif.ChangedFlagsMap
ProfilesFlagOptionPairL = map[string]string
ProfilesConfigL map[string]clif.ChangedFlagsMap
)

func (pc ProfilesConfig) Validate(name string) error {
func (pc ProfilesConfigL) Validate(name string) error {
if name != "" {
if _, found := pc[name]; !found {
return fmt.Errorf("no such profile: '%v'", name)
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/proxy-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SharedRunnerInfo struct {
Type RunnerTypeEnum
Options *nav.TraverseOptions
program Executor
profiles ProfilesConfig
profiles ProfilesConfigL
sampler *SamplerConfig
Inputs *ShrinkCommandInputs
}
Expand Down
14 changes: 12 additions & 2 deletions src/app/proxy/runner-sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/onsi/gomega"
"github.com/snivilised/cobrass/src/assistant/configuration"
ci18n "github.com/snivilised/cobrass/src/assistant/i18n"
"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"
Expand Down Expand Up @@ -44,6 +45,8 @@ var _ = Describe("SamplerRunner", Ordered, func() {
root string
config configuration.ViperConfig
nfs storage.VirtualFS
ctrl *gomock.Controller
mockConfig *mocks.MockViperConfig
)

BeforeAll(func() {
Expand Down Expand Up @@ -90,6 +93,13 @@ var _ = Describe("SamplerRunner", Ordered, func() {
if err != nil {
Fail(err.Error())
}

ctrl = gomock.NewController(GinkgoT())
mockConfig = mocks.NewMockViperConfig(ctrl)
})

AfterEach(func() {
ctrl.Finish()
})

DescribeTable("sampler",
Expand All @@ -114,13 +124,13 @@ var _ = Describe("SamplerRunner", Ordered, func() {

// this is a synthetic assignment, designed to be replaced by a mock
//
_ = mockConfig
co.Viper = &configuration.GlobalViperConfig{}
}),
}

ctrl := gomock.NewController(GinkgoT())
// m := NewMock
_ = ctrl
mocks.NewMockViperConfig(ctrl)

_, err := tester.Execute()
Expect(err).Error().To(BeNil(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/sampler-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
}
)

func (cs SamplerConfig) Validate(name string, profiles ProfilesConfig) error {
func (cs SamplerConfig) Validate(name string, profiles ProfilesConfigL) error {
if name == "" {
return nil
}
Expand Down

0 comments on commit 1982265

Please sign in to comment.