From b625dd66d7f2a948bd22357eb63c27299d5e5639 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 1 Apr 2020 14:14:27 -0500 Subject: [PATCH 1/4] Add flag sourcer and tag setter/prefixer. --- README.md | 9 ++++ consts.go | 1 + flag_sourcer.go | 103 ++++++++++++++++++++++++++++++++++++++ flag_sourcer_options.go | 30 +++++++++++ flag_sourcer_test.go | 37 ++++++++++++++ flag_tag_prefixer.go | 32 ++++++++++++ flag_tag_prefixer_test.go | 28 +++++++++++ flag_tag_setter.go | 27 ++++++++++ flag_tag_setter_test.go | 42 ++++++++++++++++ 9 files changed, 309 insertions(+) create mode 100644 flag_sourcer.go create mode 100644 flag_sourcer_options.go create mode 100644 flag_sourcer_test.go create mode 100644 flag_tag_prefixer.go create mode 100644 flag_tag_prefixer_test.go create mode 100644 flag_tag_setter.go create mode 100644 flag_tag_setter_test.go diff --git a/README.md b/README.md index 953469b..6c645e3 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ A sourcer reads values from a particular source based on a configuration struct'
Test Environment Sourcer
A test environment sourcer reads the env tag but looks up the corresponding value from a literal map. This sourcer is meant to be used in unit tests where the full construction of a nacelle [process](https://nacelle.dev/docs/core/process) is beneficial.
+
Flag Sourcer
+
A flag sourcer reads the flag tag and looks up the corresponding value attached to the process's command line arguments.
+
File Sourcer
A file sourcer reads the file tag and returns the value at the given path. A filename and a file parser musts be supplied on instantiation. Both ParseYAML and ParseTOML are supplied file parsers -- note that as JSON is a subset of YAML, ParseYAML will also correctly parse JSON files. If a nil file parser is supplied, one is chosen by the filename extension. A file sourcer will load the file tag api.timeout from the given file by parsing it into a map of values and recursively walking the (keys separated by dots). This can return a primitive type or a structured map, as long as the target field has a compatible type. The constructor NewOptionalFileSourcer will return a no-op sourcer if the filename does not exist.
@@ -117,12 +120,18 @@ A tag modifier dynamically alters the tags of a configuration struct. The follow
Display Tag Setter
A display tag setter sets the display tag to the value of the env tag. This tag modifier can be used to provide sane defaults to the tag without doubling the length of the struct tag definition.
+
Flag Tag Setter
+
A flag tag setter sets the flag tag to the value of the env tag. This tag modifier can be used to provide sane defaults to the tag without doubling the length of the struct tag definition.
+
File Tag Setter
A file tag setter sets the file tag to the value of the env tag. This tag modifier can be used to provide sane defaults to the tag without doubling the length of the struct tag definition.
Env Tag Prefixer
A environment tag prefixer inserts a prefix on each env tags. This is useful when two distinct instances of the same configuration are required, and each one should be configured independently from the other (for example, using the same abstraction to consume from two different event busses with the same consumer code).
+
Flag Tag Prefixer
+
A flag tag prefixer inserts a prefix on each flag tag. This effectively looks in a distinct top-level namespace in the parsed configuration. This is similar to the env tag prefixer.
+
File Tag Prefixer
A file tag prefixer inserts a prefix on each file tag. This effectively looks in a distinct top-level namespace in the parsed configuration. This is similar to the env tag prefixer.
diff --git a/consts.go b/consts.go index ae1b858..f7b1d46 100644 --- a/consts.go +++ b/consts.go @@ -4,6 +4,7 @@ const ( DefaultTag = "default" RequiredTag = "required" EnvTag = "env" + FlagTag = "flag" FileTag = "file" DisplayTag = "display" MaskTag = "mask" diff --git a/flag_sourcer.go b/flag_sourcer.go new file mode 100644 index 0000000..86b32a4 --- /dev/null +++ b/flag_sourcer.go @@ -0,0 +1,103 @@ +package config + +import ( + "fmt" + "strings" +) + +type flagSourcer struct { + args []string + parsed map[string]string +} + +var _ Sourcer = &flagSourcer{} + +// NewFlagSourcer creates a Sourcer that pulls values from the application +// flags. +func NewFlagSourcer(configs ...FlagSourcerConfigFunc) Sourcer { + return &flagSourcer{args: getFlagSourcerConfigOptions(configs).args} +} + +func (s *flagSourcer) Tags() []string { + return []string{FlagTag} +} + +func (s *flagSourcer) Get(values []string) (string, SourcerFlag, error) { + if values[0] == "" { + return "", FlagSkip, nil + } + + if err := s.ensureParsed(); err != nil { + return "", 0, err + } + + if val, ok := s.parsed[values[0]]; ok { + return val, FlagFound, nil + } + + return "", FlagMissing, nil +} + +func (s *flagSourcer) Assets() []string { + return []string{""} +} + +func (s *flagSourcer) Dump() (map[string]string, error) { + if err := s.ensureParsed(); err != nil { + return nil, err + } + + values := map[string]string{} + for name, value := range s.parsed { + values[name] = value + } + + return values, nil +} + +func (s *flagSourcer) ensureParsed() error { + if s.parsed != nil { + return nil + } + s.parsed = map[string]string{} + + for len(s.args) > 0 { + name, value, err := s.parseOne() + if err != nil { + return err + } + + s.parsed[name] = value + } + + return nil +} + +func (s *flagSourcer) parseOne() (string, string, error) { + arg := s.args[0] + s.args = s.args[1:] + + numMinuses := 0 + for i := 0; i < len(arg) && arg[i] == '-'; i++ { + numMinuses++ + } + + if len(arg) == 0 || numMinuses == 0 || numMinuses > 2 || (len(arg) > numMinuses && arg[numMinuses] == '=') { + return "", "", fmt.Errorf("illegal flag: %s", arg) + } + + name := arg[numMinuses:] + value := "" + + if parts := strings.SplitN(name, "=", 2); len(parts) == 2 { + name, value = parts[0], parts[1] + } else { + if len(s.args) > 0 { + value, s.args = s.args[0], s.args[1:] + } else { + return "", "", fmt.Errorf("flag needs an argument: -%s", name) + } + } + + return name, value, nil +} diff --git a/flag_sourcer_options.go b/flag_sourcer_options.go new file mode 100644 index 0000000..c99886b --- /dev/null +++ b/flag_sourcer_options.go @@ -0,0 +1,30 @@ +package config + +import "os" + +type ( + flagSourcerOptions struct { + args []string + } + + // FlagSourcerConfigFunc is a function used to configure instances of + // flag sourcers. + FlagSourcerConfigFunc func(*flagSourcerOptions) +) + +// WithFlagSourcerArgs sets raw command line arguments. +func WithFlagSourcerArgs(args []string) FlagSourcerConfigFunc { + return func(o *flagSourcerOptions) { o.args = args } +} + +func getFlagSourcerConfigOptions(configs []FlagSourcerConfigFunc) *flagSourcerOptions { + options := &flagSourcerOptions{ + args: os.Args, + } + + for _, f := range configs { + f(options) + } + + return options +} diff --git a/flag_sourcer_test.go b/flag_sourcer_test.go new file mode 100644 index 0000000..8c6f3d7 --- /dev/null +++ b/flag_sourcer_test.go @@ -0,0 +1,37 @@ +package config + +import ( + "fmt" + + "github.com/aphistic/sweet" + . "github.com/onsi/gomega" +) + +type FlagSourcerSuite struct{} + +func (s *FlagSourcerSuite) TestGet(t sweet.T) { + sourcer := NewFlagSourcer(WithFlagSourcerArgs([]string{"-X=foo", "--Y", "123"})) + val1, _, _ := sourcer.Get([]string{"X"}) + val2, _, _ := sourcer.Get([]string{"Y"}) + Expect(val1).To(Equal("foo")) + Expect(val2).To(Equal("123")) +} + +func (s *FlagSourcerSuite) TestIllegalFlag(t sweet.T) { + for _, badFlag := range []string{"X", "---X", "-=", "--="} { + _, _, err := NewFlagSourcer(WithFlagSourcerArgs([]string{badFlag})).Get([]string{"X"}) + Expect(err).To(MatchError(fmt.Sprintf("illegal flag: %s", badFlag))) + } +} + +func (s *FlagSourcerSuite) TestMissingArgument(t sweet.T) { + _, _, err := NewFlagSourcer(WithFlagSourcerArgs([]string{"--X"})).Get([]string{"X"}) + Expect(err).To(MatchError(fmt.Sprintf("flag needs an argument: -X"))) +} + +func (s *FlagSourcerSuite) TestDump(t sweet.T) { + dump, err := NewFlagSourcer(WithFlagSourcerArgs([]string{"-X=foo", "--Y", "123"})).Dump() + Expect(err).To(BeNil()) + Expect(dump["X"]).To(Equal("foo")) + Expect(dump["Y"]).To(Equal("123")) +} diff --git a/flag_tag_prefixer.go b/flag_tag_prefixer.go new file mode 100644 index 0000000..13ed4c0 --- /dev/null +++ b/flag_tag_prefixer.go @@ -0,0 +1,32 @@ +package config + +import ( + "fmt" + "reflect" + + "github.com/fatih/structtag" +) + +type flagTagPrefixer struct { + prefix string +} + +// NewFlagTagPrefixer creates a new TagModifier which adds a prefix to the +// values of `flag` tags. +func NewFlagTagPrefixer(prefix string) TagModifier { + return &flagTagPrefixer{ + prefix: prefix, + } +} + +func (p *flagTagPrefixer) AlterFieldTag(fieldType reflect.StructField, tags *structtag.Tags) error { + tag, err := tags.Get(FlagTag) + if err != nil { + return nil + } + + return tags.Set(&structtag.Tag{ + Key: FlagTag, + Name: fmt.Sprintf("%s_%s", p.prefix, tag.Name), + }) +} diff --git a/flag_tag_prefixer_test.go b/flag_tag_prefixer_test.go new file mode 100644 index 0000000..3e47d17 --- /dev/null +++ b/flag_tag_prefixer_test.go @@ -0,0 +1,28 @@ +package config + +import ( + "github.com/aphistic/sweet" + . "github.com/onsi/gomega" +) + +type FlagTagPrefixerSuite struct{} + +func (s *FlagTagPrefixerSuite) TestEnvTagPrefixer(t sweet.T) { + obj, err := ApplyTagModifiers(&BasicConfig{}, NewEnvTagPrefixer("foo")) + Expect(err).To(BeNil()) + + Expect(gatherTags(obj, "X")).To(Equal(map[string]string{ + "env": "foo_a", + "default": "q", + })) +} + +func (s *FlagTagPrefixerSuite) TestEnvTagPrefixerEmbedded(t sweet.T) { + obj, err := ApplyTagModifiers(&ParentConfig{}, NewEnvTagPrefixer("foo")) + Expect(err).To(BeNil()) + + Expect(gatherTags(obj, "X")).To(Equal(map[string]string{ + "env": "foo_a", + "default": "q", + })) +} diff --git a/flag_tag_setter.go b/flag_tag_setter.go new file mode 100644 index 0000000..f60ddea --- /dev/null +++ b/flag_tag_setter.go @@ -0,0 +1,27 @@ +package config + +import ( + "reflect" + + "github.com/fatih/structtag" +) + +type flagTagSetter struct{} + +// NewFlagTagSetter creates a new TagModifier which sets the value +// of the flag tag to be the same as the env tag. +func NewFlagTagSetter() TagModifier { + return &flagTagSetter{} +} + +func (s *flagTagSetter) AlterFieldTag(fieldType reflect.StructField, tags *structtag.Tags) error { + tagValue, err := tags.Get(EnvTag) + if err != nil { + return nil + } + + return tags.Set(&structtag.Tag{ + Key: FlagTag, + Name: tagValue.Name, + }) +} diff --git a/flag_tag_setter_test.go b/flag_tag_setter_test.go new file mode 100644 index 0000000..dcd97ea --- /dev/null +++ b/flag_tag_setter_test.go @@ -0,0 +1,42 @@ +package config + +import ( + "github.com/aphistic/sweet" + . "github.com/onsi/gomega" +) + +type FlagTagSetterSuite struct{} + +func (s *FlagTagSetterSuite) TestFlagTagSetter(t sweet.T) { + obj, err := ApplyTagModifiers( + &BasicConfig{}, + NewFlagTagSetter(), + ) + + Expect(err).To(BeNil()) + + Expect(gatherTags(obj, "X")).To(Equal(map[string]string{ + "env": "a", + "flag": "a", + "default": "q", + })) + + Expect(gatherTags(obj, "Y")).To(Equal(map[string]string{})) +} + +func (s *FlagTagSetterSuite) TestFlagTagSetterEmbedded(t sweet.T) { + obj, err := ApplyTagModifiers( + &ParentConfig{}, + NewFlagTagSetter(), + ) + + Expect(err).To(BeNil()) + + Expect(gatherTags(obj, "X")).To(Equal(map[string]string{ + "env": "a", + "flag": "a", + "default": "q", + })) + + Expect(gatherTags(obj, "Y")).To(Equal(map[string]string{})) +} From 8c505c280139470c987b5431e7daaf8977478575 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 1 Apr 2020 14:22:04 -0500 Subject: [PATCH 2/4] Add flag sourcer. --- config.go | 4 ++-- config_mock_test.go | 41 +++++++++++++++++++++------------------- env_sourcer.go | 6 ++++-- env_sourcer_test.go | 6 ++++-- error_sourcer.go | 6 ++++-- file_sourcer.go | 6 ++++-- fs_mock_test.go | 2 +- logger_mock_test.go | 2 +- logging_config.go | 9 ++++++--- main_test.go | 5 ++++- mocks/config.go | 5 +++-- mocks/sourcer.go | 5 +++-- multi_sourcer.go | 13 ++++++++++--- multi_sourcer_test.go | 10 ++++++---- sourcer.go | 2 +- sourcer_mock_test.go | 41 +++++++++++++++++++++------------------- test_env_sourcer.go | 6 ++++-- test_env_sourcer_test.go | 6 ++++-- 18 files changed, 105 insertions(+), 70 deletions(-) diff --git a/config.go b/config.go index b70078d..a9e5fca 100644 --- a/config.go +++ b/config.go @@ -29,7 +29,7 @@ type ( // is used by the logging package to show the content of the // environment and config files when a value is missing or otherwise // illegal. - Dump() map[string]string + Dump() (map[string]string, error) } // PostLoadConfig is a marker interface for configuration objects @@ -89,7 +89,7 @@ func (c *config) Assets() []string { return c.sourcer.Assets() } -func (c *config) Dump() map[string]string { +func (c *config) Dump() (map[string]string, error) { return c.sourcer.Dump() } diff --git a/config_mock_test.go b/config_mock_test.go index 77c5ab6..f5e113a 100644 --- a/config_mock_test.go +++ b/config_mock_test.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-09-05T08:24:22-05:00 +// 2020-04-01T12:23:20-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Config -o config_mock_test.go @@ -35,8 +35,8 @@ func NewMockConfig() *MockConfig { }, }, DumpFunc: &ConfigDumpFunc{ - defaultHook: func() map[string]string { - return nil + defaultHook: func() (map[string]string, error) { + return nil, nil }, }, LoadFunc: &ConfigLoadFunc{ @@ -173,23 +173,23 @@ func (c ConfigAssetsFuncCall) Results() []interface{} { // ConfigDumpFunc describes the behavior when the Dump method of the parent // MockConfig instance is invoked. type ConfigDumpFunc struct { - defaultHook func() map[string]string - hooks []func() map[string]string + defaultHook func() (map[string]string, error) + hooks []func() (map[string]string, error) history []ConfigDumpFuncCall mutex sync.Mutex } // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockConfig) Dump() map[string]string { - r0 := m.DumpFunc.nextHook()() - m.DumpFunc.appendCall(ConfigDumpFuncCall{r0}) - return r0 +func (m *MockConfig) Dump() (map[string]string, error) { + r0, r1 := m.DumpFunc.nextHook()() + m.DumpFunc.appendCall(ConfigDumpFuncCall{r0, r1}) + return r0, r1 } // SetDefaultHook sets function that is called when the Dump method of the // parent MockConfig instance is invoked and the hook queue is empty. -func (f *ConfigDumpFunc) SetDefaultHook(hook func() map[string]string) { +func (f *ConfigDumpFunc) SetDefaultHook(hook func() (map[string]string, error)) { f.defaultHook = hook } @@ -197,7 +197,7 @@ func (f *ConfigDumpFunc) SetDefaultHook(hook func() map[string]string) { // Dump method of the parent MockConfig instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. -func (f *ConfigDumpFunc) PushHook(hook func() map[string]string) { +func (f *ConfigDumpFunc) PushHook(hook func() (map[string]string, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -205,21 +205,21 @@ func (f *ConfigDumpFunc) PushHook(hook func() map[string]string) { // SetDefaultReturn calls SetDefaultDefaultHook with a function that returns // the given values. -func (f *ConfigDumpFunc) SetDefaultReturn(r0 map[string]string) { - f.SetDefaultHook(func() map[string]string { - return r0 +func (f *ConfigDumpFunc) SetDefaultReturn(r0 map[string]string, r1 error) { + f.SetDefaultHook(func() (map[string]string, error) { + return r0, r1 }) } // PushReturn calls PushDefaultHook with a function that returns the given // values. -func (f *ConfigDumpFunc) PushReturn(r0 map[string]string) { - f.PushHook(func() map[string]string { - return r0 +func (f *ConfigDumpFunc) PushReturn(r0 map[string]string, r1 error) { + f.PushHook(func() (map[string]string, error) { + return r0, r1 }) } -func (f *ConfigDumpFunc) nextHook() func() map[string]string { +func (f *ConfigDumpFunc) nextHook() func() (map[string]string, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -255,6 +255,9 @@ type ConfigDumpFuncCall struct { // Result0 is the value of the 1st result returned from this method // invocation. Result0 map[string]string + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error } // Args returns an interface slice containing the arguments of this @@ -266,7 +269,7 @@ func (c ConfigDumpFuncCall) Args() []interface{} { // Results returns an interface slice containing the results of this // invocation. func (c ConfigDumpFuncCall) Results() []interface{} { - return []interface{}{c.Result0} + return []interface{}{c.Result0, c.Result1} } // ConfigLoadFunc describes the behavior when the Load method of the parent diff --git a/env_sourcer.go b/env_sourcer.go index f3e6557..1b3f469 100644 --- a/env_sourcer.go +++ b/env_sourcer.go @@ -11,6 +11,8 @@ type envSourcer struct { prefix string } +var _ Sourcer = &envSourcer{} + var replacePattern = regexp.MustCompile(`[^A-Za-z0-9_]+`) // NewEnvSourcer creates a Sourcer that pulls values from the environment. @@ -58,13 +60,13 @@ func (s *envSourcer) Assets() []string { return []string{""} } -func (s *envSourcer) Dump() map[string]string { +func (s *envSourcer) Dump() (map[string]string, error) { values := map[string]string{} for _, name := range getNames() { values[name] = os.Getenv(name) } - return values + return values, nil } func getNames() []string { diff --git a/env_sourcer_test.go b/env_sourcer_test.go index 1028497..96e916d 100644 --- a/env_sourcer_test.go +++ b/env_sourcer_test.go @@ -36,6 +36,8 @@ func (s *EnvSourcerSuite) TestDump(t sweet.T) { os.Setenv("X", "foo") os.Setenv("Y", "123") - Expect(NewEnvSourcer("app").Dump()["X"]).To(Equal("foo")) - Expect(NewEnvSourcer("app").Dump()["Y"]).To(Equal("123")) + dump, err := NewEnvSourcer("app").Dump() + Expect(err).To(BeNil()) + Expect(dump["X"]).To(Equal("foo")) + Expect(dump["Y"]).To(Equal("123")) } diff --git a/error_sourcer.go b/error_sourcer.go index 915c9c3..f17fd11 100644 --- a/error_sourcer.go +++ b/error_sourcer.go @@ -4,6 +4,8 @@ type errorSourcer struct { err error } +var _ Sourcer = &errorSourcer{} + func newErrorSourcer(err error) Sourcer { return &errorSourcer{err} } @@ -20,6 +22,6 @@ func (s *errorSourcer) Assets() []string { return nil } -func (s *errorSourcer) Dump() map[string]string { - return nil +func (s *errorSourcer) Dump() (map[string]string, error) { + return nil, s.err } diff --git a/file_sourcer.go b/file_sourcer.go index 0a5cf83..89d8a05 100644 --- a/file_sourcer.go +++ b/file_sourcer.go @@ -19,6 +19,8 @@ type ( FileParser func(content []byte) (map[string]interface{}, error) ) +var _ Sourcer = &fileSourcer{} + var parserMap = map[string]FileParser{ ".yaml": ParseYAML, ".yml": ParseYAML, @@ -91,8 +93,8 @@ func (s *fileSourcer) Assets() []string { return []string{s.filename} } -func (s *fileSourcer) Dump() map[string]string { - return s.values +func (s *fileSourcer) Dump() (map[string]string, error) { + return s.values, nil } // diff --git a/fs_mock_test.go b/fs_mock_test.go index cda9151..d8e60c6 100644 --- a/fs_mock_test.go +++ b/fs_mock_test.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-09-05T08:24:25-05:00 +// 2020-04-01T12:23:23-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i FileSystem -o fs_mock_test.go diff --git a/logger_mock_test.go b/logger_mock_test.go index 0eefe0a..d57b268 100644 --- a/logger_mock_test.go +++ b/logger_mock_test.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-09-05T08:24:23-05:00 +// 2020-04-01T12:23:21-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Logger -o logger_mock_test.go diff --git a/logging_config.go b/logging_config.go index 10fe317..ee17d57 100644 --- a/logging_config.go +++ b/logging_config.go @@ -56,10 +56,13 @@ func (c *loggingConfig) MustLoad(target interface{}, modifiers ...TagModifier) { } func (c *loggingConfig) dumpSource() error { - assets := strings.Join(c.Config.Assets(), ", ") + dump, err := c.Config.Dump() + if err != nil { + return err + } chunk := map[string]interface{}{} - for key, value := range c.Config.Dump() { + for key, value := range dump { if c.isMasked(key) { chunk[key] = "*****" } else { @@ -67,7 +70,7 @@ func (c *loggingConfig) dumpSource() error { } } - c.logger.Printf("Config source assets: %s", assets) + c.logger.Printf("Config source assets: %s", strings.Join(c.Config.Assets(), ", ")) c.logger.Printf("Config source contents: %s", normalizeChunk(chunk)) return nil } diff --git a/main_test.go b/main_test.go index de855ee..5e0fa31 100644 --- a/main_test.go +++ b/main_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/aphistic/sweet" - "github.com/aphistic/sweet-junit" + junit "github.com/aphistic/sweet-junit" "github.com/fatih/structtag" . "github.com/onsi/gomega" ) @@ -27,6 +27,9 @@ func TestMain(m *testing.M) { s.AddSuite(&DisplayTagSetterSuite{}) s.AddSuite(&EnvSourcerSuite{}) s.AddSuite(&EnvTagPrefixerSuite{}) + s.AddSuite(&FlagSourcerSuite{}) + s.AddSuite(&FlagTagPrefixerSuite{}) + s.AddSuite(&FlagTagSetterSuite{}) s.AddSuite(&FileSourcerSuite{}) s.AddSuite(&FileTagPrefixerSuite{}) s.AddSuite(&FileTagSetterSuite{}) diff --git a/mocks/config.go b/mocks/config.go index d2f9a05..241430b 100644 --- a/mocks/config.go +++ b/mocks/config.go @@ -7,8 +7,9 @@ package mocks import ( - config "github.com/go-nacelle/config" "sync" + + config "github.com/go-nacelle/config" ) // MockConfig is a mock implementation of the Config interface (from the @@ -184,7 +185,7 @@ type ConfigDumpFunc struct { // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockConfig) Dump() map[string]string { +func (m *MockConfig) Dump() (map[string]string, error) { r0 := m.DumpFunc.nextHook()() m.DumpFunc.appendCall(ConfigDumpFuncCall{r0}) return r0 diff --git a/mocks/sourcer.go b/mocks/sourcer.go index 8185a77..3c095b4 100644 --- a/mocks/sourcer.go +++ b/mocks/sourcer.go @@ -7,8 +7,9 @@ package mocks import ( - config "github.com/go-nacelle/config" "sync" + + config "github.com/go-nacelle/config" ) // MockSourcer is a mock implementation of the Sourcer interface (from the @@ -184,7 +185,7 @@ type SourcerDumpFunc struct { // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockSourcer) Dump() map[string]string { +func (m *MockSourcer) Dump() (map[string]string, error) { r0 := m.DumpFunc.nextHook()() m.DumpFunc.appendCall(SourcerDumpFuncCall{r0}) return r0 diff --git a/multi_sourcer.go b/multi_sourcer.go index b3409ec..24d7cd5 100644 --- a/multi_sourcer.go +++ b/multi_sourcer.go @@ -9,6 +9,8 @@ type multiSourcer struct { tags []string } +var _ Sourcer = &multiSourcer{} + // NewMultiSourcer creates a sourcer that reads form each sourcer. // The last value found is returned - sourcers should be provided // from low priority to high priority. @@ -80,13 +82,18 @@ func (s *multiSourcer) Assets() []string { return assets } -func (s *multiSourcer) Dump() map[string]string { +func (s *multiSourcer) Dump() (map[string]string, error) { values := map[string]string{} for i := len(s.sourcers) - 1; i >= 0; i-- { - for k, v := range s.sourcers[i].Dump() { + dump, err := s.sourcers[i].Dump() + if err != nil { + return nil, err + } + + for k, v := range dump { values[k] = v } } - return values + return values, nil } diff --git a/multi_sourcer_test.go b/multi_sourcer_test.go index 307b51a..5047135 100644 --- a/multi_sourcer_test.go +++ b/multi_sourcer_test.go @@ -108,11 +108,13 @@ func (s *MultiSourcerSuite) TestDump(t sweet.T) { s1 := NewMockSourcer() s2 := NewMockSourcer() s3 := NewMockSourcer() - s1.DumpFunc.SetDefaultReturn(map[string]string{"a": "foo"}) - s2.DumpFunc.SetDefaultReturn(map[string]string{"b": "bar", "a": "bonk"}) - s3.DumpFunc.SetDefaultReturn(map[string]string{"c": "baz"}) + s1.DumpFunc.SetDefaultReturn(map[string]string{"a": "foo"}, nil) + s2.DumpFunc.SetDefaultReturn(map[string]string{"b": "bar", "a": "bonk"}, nil) + s3.DumpFunc.SetDefaultReturn(map[string]string{"c": "baz"}, nil) - Expect(NewMultiSourcer(s3, s2, s1).Dump()).To(Equal(map[string]string{ + dump, err := NewMultiSourcer(s3, s2, s1).Dump() + Expect(err).To(BeNil()) + Expect(dump).To(Equal(map[string]string{ "a": "bonk", "b": "bar", "c": "baz", diff --git a/sourcer.go b/sourcer.go index 4544b9a..f2cae6d 100644 --- a/sourcer.go +++ b/sourcer.go @@ -25,7 +25,7 @@ type ( // Dump returns the full content of the sourcer. This is used by the // logging package to show the content of the environment and config // files when a value is missing or otherwise illegal. - Dump() map[string]string + Dump() (map[string]string, error) } SourcerFlag int diff --git a/sourcer_mock_test.go b/sourcer_mock_test.go index 33feafa..46b45b3 100644 --- a/sourcer_mock_test.go +++ b/sourcer_mock_test.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-09-05T08:24:24-05:00 +// 2020-04-01T12:23:22-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Sourcer -o sourcer_mock_test.go @@ -35,8 +35,8 @@ func NewMockSourcer() *MockSourcer { }, }, DumpFunc: &SourcerDumpFunc{ - defaultHook: func() map[string]string { - return nil + defaultHook: func() (map[string]string, error) { + return nil, nil }, }, GetFunc: &SourcerGetFunc{ @@ -173,23 +173,23 @@ func (c SourcerAssetsFuncCall) Results() []interface{} { // SourcerDumpFunc describes the behavior when the Dump method of the parent // MockSourcer instance is invoked. type SourcerDumpFunc struct { - defaultHook func() map[string]string - hooks []func() map[string]string + defaultHook func() (map[string]string, error) + hooks []func() (map[string]string, error) history []SourcerDumpFuncCall mutex sync.Mutex } // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockSourcer) Dump() map[string]string { - r0 := m.DumpFunc.nextHook()() - m.DumpFunc.appendCall(SourcerDumpFuncCall{r0}) - return r0 +func (m *MockSourcer) Dump() (map[string]string, error) { + r0, r1 := m.DumpFunc.nextHook()() + m.DumpFunc.appendCall(SourcerDumpFuncCall{r0, r1}) + return r0, r1 } // SetDefaultHook sets function that is called when the Dump method of the // parent MockSourcer instance is invoked and the hook queue is empty. -func (f *SourcerDumpFunc) SetDefaultHook(hook func() map[string]string) { +func (f *SourcerDumpFunc) SetDefaultHook(hook func() (map[string]string, error)) { f.defaultHook = hook } @@ -197,7 +197,7 @@ func (f *SourcerDumpFunc) SetDefaultHook(hook func() map[string]string) { // Dump method of the parent MockSourcer instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. -func (f *SourcerDumpFunc) PushHook(hook func() map[string]string) { +func (f *SourcerDumpFunc) PushHook(hook func() (map[string]string, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -205,21 +205,21 @@ func (f *SourcerDumpFunc) PushHook(hook func() map[string]string) { // SetDefaultReturn calls SetDefaultDefaultHook with a function that returns // the given values. -func (f *SourcerDumpFunc) SetDefaultReturn(r0 map[string]string) { - f.SetDefaultHook(func() map[string]string { - return r0 +func (f *SourcerDumpFunc) SetDefaultReturn(r0 map[string]string, r1 error) { + f.SetDefaultHook(func() (map[string]string, error) { + return r0, r1 }) } // PushReturn calls PushDefaultHook with a function that returns the given // values. -func (f *SourcerDumpFunc) PushReturn(r0 map[string]string) { - f.PushHook(func() map[string]string { - return r0 +func (f *SourcerDumpFunc) PushReturn(r0 map[string]string, r1 error) { + f.PushHook(func() (map[string]string, error) { + return r0, r1 }) } -func (f *SourcerDumpFunc) nextHook() func() map[string]string { +func (f *SourcerDumpFunc) nextHook() func() (map[string]string, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -255,6 +255,9 @@ type SourcerDumpFuncCall struct { // Result0 is the value of the 1st result returned from this method // invocation. Result0 map[string]string + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error } // Args returns an interface slice containing the arguments of this @@ -266,7 +269,7 @@ func (c SourcerDumpFuncCall) Args() []interface{} { // Results returns an interface slice containing the results of this // invocation. func (c SourcerDumpFuncCall) Results() []interface{} { - return []interface{}{c.Result0} + return []interface{}{c.Result0, c.Result1} } // SourcerGetFunc describes the behavior when the Get method of the parent diff --git a/test_env_sourcer.go b/test_env_sourcer.go index 4ab85d7..b5bd9bc 100644 --- a/test_env_sourcer.go +++ b/test_env_sourcer.go @@ -8,6 +8,8 @@ type testEnvSourcer struct { values map[string]string } +var _ Sourcer = &testEnvSourcer{} + // NewTestEnvSourcer creates a Sourcer that returns values from a given // map. func NewTestEnvSourcer(values map[string]string) Sourcer { @@ -41,6 +43,6 @@ func (s *testEnvSourcer) Assets() []string { return []string{""} } -func (s *testEnvSourcer) Dump() map[string]string { - return s.values +func (s *testEnvSourcer) Dump() (map[string]string, error) { + return s.values, nil } diff --git a/test_env_sourcer_test.go b/test_env_sourcer_test.go index feedbad..5f189df 100644 --- a/test_env_sourcer_test.go +++ b/test_env_sourcer_test.go @@ -39,6 +39,8 @@ func (s *TestEnvSourcerSuite) TestDump(t sweet.T) { "Y": "123", } - Expect(NewTestEnvSourcer(values).Dump()["X"]).To(Equal("foo")) - Expect(NewTestEnvSourcer(values).Dump()["Y"]).To(Equal("123")) + dump, err := NewTestEnvSourcer(values).Dump() + Expect(err).To(BeNil()) + Expect(dump["X"]).To(Equal("foo")) + Expect(dump["Y"]).To(Equal("123")) } From 14a896aa1b85b3b5e34338b0d3b07ca261f7e902 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 1 Apr 2020 14:22:49 -0500 Subject: [PATCH 3/4] Fix os.Args offset. --- flag_sourcer_options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flag_sourcer_options.go b/flag_sourcer_options.go index c99886b..ead57b8 100644 --- a/flag_sourcer_options.go +++ b/flag_sourcer_options.go @@ -19,7 +19,7 @@ func WithFlagSourcerArgs(args []string) FlagSourcerConfigFunc { func getFlagSourcerConfigOptions(configs []FlagSourcerConfigFunc) *flagSourcerOptions { options := &flagSourcerOptions{ - args: os.Args, + args: os.Args[1:], } for _, f := range configs { From 58852448c450c9fa7290ca031784b5bf11fe2ebc Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 1 Apr 2020 14:24:39 -0500 Subject: [PATCH 4/4] Regenerate mocks. --- mocks/config.go | 52 ++++++++++++++++++++++--------------------- mocks/logger.go | 6 ++--- mocks/sourcer.go | 52 ++++++++++++++++++++++--------------------- mocks/tag_modifier.go | 6 ++--- 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/mocks/config.go b/mocks/config.go index 241430b..1ee6dcd 100644 --- a/mocks/config.go +++ b/mocks/config.go @@ -1,18 +1,17 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-06-17T20:19:18-05:00 +// 2020-04-01T14:24:05-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Config -o config.go package mocks import ( - "sync" - config "github.com/go-nacelle/config" + "sync" ) -// MockConfig is a mock implementation of the Config interface (from the +// MockConfig is a mock impelementation of the Config interface (from the // package github.com/go-nacelle/config) used for unit testing. type MockConfig struct { // AssetsFunc is an instance of a mock function object controlling the @@ -39,8 +38,8 @@ func NewMockConfig() *MockConfig { }, }, DumpFunc: &ConfigDumpFunc{ - defaultHook: func() map[string]string { - return nil + defaultHook: func() (map[string]string, error) { + return nil, nil }, }, LoadFunc: &ConfigLoadFunc{ @@ -99,7 +98,7 @@ func (f *ConfigAssetsFunc) SetDefaultHook(hook func() []string) { } // PushHook adds a function to the end of hook queue. Each invocation of the -// Assets method of the parent MockConfig instance invokes the hook at the +// Assets method of the parent MockConfig instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *ConfigAssetsFunc) PushHook(hook func() []string) { @@ -177,8 +176,8 @@ func (c ConfigAssetsFuncCall) Results() []interface{} { // ConfigDumpFunc describes the behavior when the Dump method of the parent // MockConfig instance is invoked. type ConfigDumpFunc struct { - defaultHook func() map[string]string - hooks []func() map[string]string + defaultHook func() (map[string]string, error) + hooks []func() (map[string]string, error) history []ConfigDumpFuncCall mutex sync.Mutex } @@ -186,22 +185,22 @@ type ConfigDumpFunc struct { // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. func (m *MockConfig) Dump() (map[string]string, error) { - r0 := m.DumpFunc.nextHook()() - m.DumpFunc.appendCall(ConfigDumpFuncCall{r0}) - return r0 + r0, r1 := m.DumpFunc.nextHook()() + m.DumpFunc.appendCall(ConfigDumpFuncCall{r0, r1}) + return r0, r1 } // SetDefaultHook sets function that is called when the Dump method of the // parent MockConfig instance is invoked and the hook queue is empty. -func (f *ConfigDumpFunc) SetDefaultHook(hook func() map[string]string) { +func (f *ConfigDumpFunc) SetDefaultHook(hook func() (map[string]string, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Dump method of the parent MockConfig instance invokes the hook at the +// Dump method of the parent MockConfig instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. -func (f *ConfigDumpFunc) PushHook(hook func() map[string]string) { +func (f *ConfigDumpFunc) PushHook(hook func() (map[string]string, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -209,21 +208,21 @@ func (f *ConfigDumpFunc) PushHook(hook func() map[string]string) { // SetDefaultReturn calls SetDefaultDefaultHook with a function that returns // the given values. -func (f *ConfigDumpFunc) SetDefaultReturn(r0 map[string]string) { - f.SetDefaultHook(func() map[string]string { - return r0 +func (f *ConfigDumpFunc) SetDefaultReturn(r0 map[string]string, r1 error) { + f.SetDefaultHook(func() (map[string]string, error) { + return r0, r1 }) } // PushReturn calls PushDefaultHook with a function that returns the given // values. -func (f *ConfigDumpFunc) PushReturn(r0 map[string]string) { - f.PushHook(func() map[string]string { - return r0 +func (f *ConfigDumpFunc) PushReturn(r0 map[string]string, r1 error) { + f.PushHook(func() (map[string]string, error) { + return r0, r1 }) } -func (f *ConfigDumpFunc) nextHook() func() map[string]string { +func (f *ConfigDumpFunc) nextHook() func() (map[string]string, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -259,6 +258,9 @@ type ConfigDumpFuncCall struct { // Result0 is the value of the 1st result returned from this method // invocation. Result0 map[string]string + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error } // Args returns an interface slice containing the arguments of this @@ -270,7 +272,7 @@ func (c ConfigDumpFuncCall) Args() []interface{} { // Results returns an interface slice containing the results of this // invocation. func (c ConfigDumpFuncCall) Results() []interface{} { - return []interface{}{c.Result0} + return []interface{}{c.Result0, c.Result1} } // ConfigLoadFunc describes the behavior when the Load method of the parent @@ -297,7 +299,7 @@ func (f *ConfigLoadFunc) SetDefaultHook(hook func(interface{}, ...config.TagModi } // PushHook adds a function to the end of hook queue. Each invocation of the -// Load method of the parent MockConfig instance invokes the hook at the +// Load method of the parent MockConfig instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *ConfigLoadFunc) PushHook(hook func(interface{}, ...config.TagModifier) error) { @@ -409,7 +411,7 @@ func (f *ConfigMustLoadFunc) SetDefaultHook(hook func(interface{}, ...config.Tag } // PushHook adds a function to the end of hook queue. Each invocation of the -// MustLoad method of the parent MockConfig instance invokes the hook at the +// MustLoad method of the parent MockConfig instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *ConfigMustLoadFunc) PushHook(hook func(interface{}, ...config.TagModifier)) { diff --git a/mocks/logger.go b/mocks/logger.go index 41fa8f2..3402f13 100644 --- a/mocks/logger.go +++ b/mocks/logger.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-06-17T20:19:19-05:00 +// 2020-04-01T14:24:06-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Logger -o logger.go @@ -11,7 +11,7 @@ import ( "sync" ) -// MockLogger is a mock implementation of the Logger interface (from the +// MockLogger is a mock impelementation of the Logger interface (from the // package github.com/go-nacelle/config) used for unit testing. type MockLogger struct { // PrintfFunc is an instance of a mock function object controlling the @@ -65,7 +65,7 @@ func (f *LoggerPrintfFunc) SetDefaultHook(hook func(string, ...interface{})) { } // PushHook adds a function to the end of hook queue. Each invocation of the -// Printf method of the parent MockLogger instance invokes the hook at the +// Printf method of the parent MockLogger instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *LoggerPrintfFunc) PushHook(hook func(string, ...interface{})) { diff --git a/mocks/sourcer.go b/mocks/sourcer.go index 3c095b4..16ae639 100644 --- a/mocks/sourcer.go +++ b/mocks/sourcer.go @@ -1,18 +1,17 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-06-17T20:19:20-05:00 +// 2020-04-01T14:24:07-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i Sourcer -o sourcer.go package mocks import ( - "sync" - config "github.com/go-nacelle/config" + "sync" ) -// MockSourcer is a mock implementation of the Sourcer interface (from the +// MockSourcer is a mock impelementation of the Sourcer interface (from the // package github.com/go-nacelle/config) used for unit testing. type MockSourcer struct { // AssetsFunc is an instance of a mock function object controlling the @@ -39,8 +38,8 @@ func NewMockSourcer() *MockSourcer { }, }, DumpFunc: &SourcerDumpFunc{ - defaultHook: func() map[string]string { - return nil + defaultHook: func() (map[string]string, error) { + return nil, nil }, }, GetFunc: &SourcerGetFunc{ @@ -99,7 +98,7 @@ func (f *SourcerAssetsFunc) SetDefaultHook(hook func() []string) { } // PushHook adds a function to the end of hook queue. Each invocation of the -// Assets method of the parent MockSourcer instance invokes the hook at the +// Assets method of the parent MockSourcer instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *SourcerAssetsFunc) PushHook(hook func() []string) { @@ -177,8 +176,8 @@ func (c SourcerAssetsFuncCall) Results() []interface{} { // SourcerDumpFunc describes the behavior when the Dump method of the parent // MockSourcer instance is invoked. type SourcerDumpFunc struct { - defaultHook func() map[string]string - hooks []func() map[string]string + defaultHook func() (map[string]string, error) + hooks []func() (map[string]string, error) history []SourcerDumpFuncCall mutex sync.Mutex } @@ -186,22 +185,22 @@ type SourcerDumpFunc struct { // Dump delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. func (m *MockSourcer) Dump() (map[string]string, error) { - r0 := m.DumpFunc.nextHook()() - m.DumpFunc.appendCall(SourcerDumpFuncCall{r0}) - return r0 + r0, r1 := m.DumpFunc.nextHook()() + m.DumpFunc.appendCall(SourcerDumpFuncCall{r0, r1}) + return r0, r1 } // SetDefaultHook sets function that is called when the Dump method of the // parent MockSourcer instance is invoked and the hook queue is empty. -func (f *SourcerDumpFunc) SetDefaultHook(hook func() map[string]string) { +func (f *SourcerDumpFunc) SetDefaultHook(hook func() (map[string]string, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// Dump method of the parent MockSourcer instance invokes the hook at the +// Dump method of the parent MockSourcer instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. -func (f *SourcerDumpFunc) PushHook(hook func() map[string]string) { +func (f *SourcerDumpFunc) PushHook(hook func() (map[string]string, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -209,21 +208,21 @@ func (f *SourcerDumpFunc) PushHook(hook func() map[string]string) { // SetDefaultReturn calls SetDefaultDefaultHook with a function that returns // the given values. -func (f *SourcerDumpFunc) SetDefaultReturn(r0 map[string]string) { - f.SetDefaultHook(func() map[string]string { - return r0 +func (f *SourcerDumpFunc) SetDefaultReturn(r0 map[string]string, r1 error) { + f.SetDefaultHook(func() (map[string]string, error) { + return r0, r1 }) } // PushReturn calls PushDefaultHook with a function that returns the given // values. -func (f *SourcerDumpFunc) PushReturn(r0 map[string]string) { - f.PushHook(func() map[string]string { - return r0 +func (f *SourcerDumpFunc) PushReturn(r0 map[string]string, r1 error) { + f.PushHook(func() (map[string]string, error) { + return r0, r1 }) } -func (f *SourcerDumpFunc) nextHook() func() map[string]string { +func (f *SourcerDumpFunc) nextHook() func() (map[string]string, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -259,6 +258,9 @@ type SourcerDumpFuncCall struct { // Result0 is the value of the 1st result returned from this method // invocation. Result0 map[string]string + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error } // Args returns an interface slice containing the arguments of this @@ -270,7 +272,7 @@ func (c SourcerDumpFuncCall) Args() []interface{} { // Results returns an interface slice containing the results of this // invocation. func (c SourcerDumpFuncCall) Results() []interface{} { - return []interface{}{c.Result0} + return []interface{}{c.Result0, c.Result1} } // SourcerGetFunc describes the behavior when the Get method of the parent @@ -297,7 +299,7 @@ func (f *SourcerGetFunc) SetDefaultHook(hook func([]string) (string, config.Sour } // PushHook adds a function to the end of hook queue. Each invocation of the -// Get method of the parent MockSourcer instance invokes the hook at the +// Get method of the parent MockSourcer instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *SourcerGetFunc) PushHook(hook func([]string) (string, config.SourcerFlag, error)) { @@ -405,7 +407,7 @@ func (f *SourcerTagsFunc) SetDefaultHook(hook func() []string) { } // PushHook adds a function to the end of hook queue. Each invocation of the -// Tags method of the parent MockSourcer instance invokes the hook at the +// Tags method of the parent MockSourcer instance inovkes the hook at the // front of the queue and discards it. After the queue is empty, the default // hook function is invoked for any future action. func (f *SourcerTagsFunc) PushHook(hook func() []string) { diff --git a/mocks/tag_modifier.go b/mocks/tag_modifier.go index 0f7b168..060bef7 100644 --- a/mocks/tag_modifier.go +++ b/mocks/tag_modifier.go @@ -1,6 +1,6 @@ // Code generated by github.com/efritz/go-mockgen 0.1.0; DO NOT EDIT. // This file was generated by robots at -// 2019-06-17T20:19:21-05:00 +// 2020-04-01T14:24:08-05:00 // using the command // $ go-mockgen -f github.com/go-nacelle/config -i TagModifier -o tag_modifier.go @@ -13,7 +13,7 @@ import ( "sync" ) -// MockTagModifier is a mock implementation of the TagModifier interface +// MockTagModifier is a mock impelementation of the TagModifier interface // (from the package github.com/go-nacelle/config) used for unit testing. type MockTagModifier struct { // AlterFieldTagFunc is an instance of a mock function object @@ -69,7 +69,7 @@ func (f *TagModifierAlterFieldTagFunc) SetDefaultHook(hook func(reflect.StructFi } // PushHook adds a function to the end of hook queue. Each invocation of the -// AlterFieldTag method of the parent MockTagModifier instance invokes the +// AlterFieldTag method of the parent MockTagModifier instance inovkes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. func (f *TagModifierAlterFieldTagFunc) PushHook(hook func(reflect.StructField, *structtag.Tags) error) {