Skip to content

Commit 1aab060

Browse files
authored
fix: minor tweaks and comment removals (#30)
1 parent f762b83 commit 1aab060

File tree

7 files changed

+5
-196
lines changed

7 files changed

+5
-196
lines changed

cmd/configmanager/configmanager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func cmdRunTestHelper(t *testing.T, testInput *cmdTestInput) {
3131
leveler.Set(testInput.logLevel)
3232

3333
logErr := &bytes.Buffer{}
34-
logger := log.New(logErr) //slog.New(slog.NewTextHandler(logErr, &slog.HandlerOptions{Level: leveler}))
34+
logger := log.New(logErr)
3535
cmd := cmd.NewRootCmd(logger)
3636
os.Args = append([]string{os.Args[0]}, testInput.args...)
3737
errOut := &bytes.Buffer{}

cmd/configmanager/fromfileinput.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ func newFromStrCmd(rootCmd *Root) {
5050
fromstrCmd.PersistentFlags().StringVarP(&f.path, "path", "p", "./app.env", `Path where to write out the
5151
replaced a config/secret variables. Special value of stdout can be used to return the output to stdout e.g. -p stdout,
5252
unix style output only`)
53-
// retrieveFromStrInput.PersistentFlags().BoolVarP(&overwriteinputfile, "overwrite", "o", false, `Writes the outputs of the templated file
54-
// to a the same location as the input file path`)
5553
rootCmd.Cmd.AddCommand(fromstrCmd)
5654
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
app:
2-
conf: UNKNOWN://foo/bar
2+
conf: UNKNOWN://foo/bar

cmd/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
)
1010

1111
func main() {
12-
// leveler := &slog.LevelVar{}
13-
// logger := log.slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: leveler}))
1412
logger := log.New(os.Stderr)
1513
cmd := cfgmgr.NewRootCmd(logger)
1614
if err := cmd.Execute(context.Background()); err != nil {

configmanager_test.go

Lines changed: 2 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,10 @@ import (
1414
"github.com/go-test/deep"
1515
)
1616

17-
// type mockConfigManageriface interface {
18-
// Retrieve(tokens []string, config generator.GenVarsConfig) (generator.ParsedMap, error)
19-
// RetrieveWithInputReplaced(input string, config generator.GenVarsConfig) (string, error)
20-
// Insert(force bool) error
21-
// }
22-
2317
type mockGenerator struct {
2418
generate func(tokens []string) (generator.ParsedMap, error)
2519
}
2620

27-
// var (
28-
// testKey = "FOO#/test"
29-
// testVal = "val1"
30-
// )
31-
3221
func (m *mockGenerator) Generate(tokens []string) (generator.ParsedMap, error) {
3322
if m.generate != nil {
3423
return m.generate(tokens)
@@ -40,14 +29,10 @@ func (m *mockGenerator) Generate(tokens []string) (generator.ParsedMap, error) {
4029
return pm, nil
4130
}
4231

43-
type mockGenIface interface {
44-
Generate(tokens []string) (generator.ParsedMap, error)
45-
}
46-
4732
func Test_Retrieve_from_token_list(t *testing.T) {
4833
tests := map[string]struct {
4934
tokens []string
50-
genvar mockGenIface
35+
genvar *mockGenerator
5136
expectKey string
5237
expectVal string
5338
}{
@@ -81,7 +66,7 @@ func Test_retrieveWithInputReplaced(t *testing.T) {
8166
tests := map[string]struct {
8267
name string
8368
input string
84-
genvar mockGenIface
69+
genvar *mockGenerator
8570
expect string
8671
}{
8772
"strYaml": {
@@ -184,44 +169,6 @@ foo23 = val1
184169
}
185170
}
186171

187-
// func Test_replaceString(t *testing.T) {
188-
// tests := []struct {
189-
// name string
190-
// parsedMap generator.ParsedMap
191-
// inputStr string
192-
// expectStr string
193-
// }{
194-
// {
195-
// name: "ordered correctly",
196-
// parsedMap: generator.ParsedMap{
197-
// "AZKVSECRET#/test-vault/db-config|user": "foo",
198-
// "AZKVSECRET#/test-vault/db-config|pass": "bar",
199-
// "AZKVSECRET#/test-vault/db-config": fmt.Sprintf("%v", "{\"user\": \"foo\", \"pass\": \"bar\"}"),
200-
// },
201-
// inputStr: `app: foo
202-
// db2: AZKVSECRET#/test-vault/db-config
203-
// db:
204-
// user: AZKVSECRET#/test-vault/db-config|user
205-
// pass: AZKVSECRET#/test-vault/db-config|pass
206-
// `,
207-
// expectStr: `app: foo
208-
// db2: {"user": "foo", "pass": "bar"}
209-
// db:
210-
// user: foo
211-
// pass: bar
212-
// `,
213-
// },
214-
// }
215-
// for _, tt := range tests {
216-
// t.Run(tt.name, func(t *testing.T) {
217-
// got := replaceString(tt.parsedMap, tt.inputStr)
218-
// if got != tt.expectStr {
219-
// t.Errorf(testutils.TestPhrase, got, tt.expectStr)
220-
// }
221-
// })
222-
// }
223-
// }
224-
225172
type testSimpleStruct struct {
226173
Foo string `json:"foo" yaml:"foo"`
227174
Bar string `json:"bar" yaml:"bar"`
@@ -558,9 +505,6 @@ func Test_YamlRetrieveMarshalled_errored_in_marshal(t *testing.T) {
558505
c := configmanager.New(context.TODO())
559506
c.Config.WithTokenSeparator("://")
560507
c.WithGenerator(m)
561-
// input := &testNestedStruct{}
562-
// var errYaml = func() {}
563-
// type failingMarshaler struct{}
564508
err := c.RetrieveMarshalledYaml(&struct {
565509
A int
566510
B map[string]int `yaml:",inline"`
@@ -644,116 +588,3 @@ func Test_Generator_Config_(t *testing.T) {
644588
})
645589
}
646590
}
647-
648-
// func Test_KubeControllerSpecHelper(t *testing.T) {
649-
// tests := []struct {
650-
// name string
651-
// testType testSimpleStruct
652-
// expect testSimpleStruct
653-
// cfmgr func(t *testing.T) mockConfigManageriface
654-
// }{
655-
// {
656-
// name: "happy path simple struct",
657-
// testType: testSimpleStruct{
658-
// Foo: testTokenAWS,
659-
// Bar: "quz",
660-
// },
661-
// expect: testSimpleStruct{
662-
// Foo: "baz",
663-
// Bar: "quz",
664-
// },
665-
// cfmgr: func(t *testing.T) mockConfigManageriface {
666-
// mcm := &MockCfgMgr{}
667-
// mcm.retrieveInput = func(input string, config generator.GenVarsConfig) (string, error) {
668-
// return `{"foo":"baz","bar":"quz"}`, nil
669-
// }
670-
// return mcm
671-
// },
672-
// },
673-
// {
674-
// name: "happy path simple struct2",
675-
// testType: testSimpleStruct{
676-
// Foo: "AWSSECRETS:///bar/foo2",
677-
// Bar: "quz",
678-
// },
679-
// expect: testSimpleStruct{
680-
// Foo: "baz2",
681-
// Bar: "quz",
682-
// },
683-
// cfmgr: func(t *testing.T) mockConfigManageriface {
684-
// mcm := &MockCfgMgr{}
685-
// mcm.retrieveInput = func(input string, config generator.GenVarsConfig) (string, error) {
686-
// return `{"foo":"baz2","bar":"quz"}`, nil
687-
// }
688-
// return mcm
689-
// },
690-
// },
691-
// }
692-
// for _, tt := range tests {
693-
// t.Run(tt.name, func(t *testing.T) {
694-
695-
// config := generator.NewConfig()
696-
// resp, err := KubeControllerSpecHelper(tt.testType, tt.cfmgr(t), *config)
697-
// if err != nil {
698-
// t.Errorf(testutils.TestPhrase, err.Error(), nil)
699-
// }
700-
// if !reflect.DeepEqual(resp, &tt.expect) {
701-
// t.Error("")
702-
// }
703-
// })
704-
// }
705-
// }
706-
707-
// func Test_KubeControllerComplex(t *testing.T) {
708-
// tests := []struct {
709-
// name string
710-
// testType testNestedStruct
711-
// expect testNestedStruct
712-
// cfmgr func(t *testing.T) mockConfigManageriface
713-
// }{
714-
// {
715-
// name: "happy path complex struct",
716-
// testType: testNestedStruct{
717-
// Foo: testTokenAWS,
718-
// Bar: "quz",
719-
// Lol: testLol{
720-
// Bla: "booo",
721-
// Another: testAnotherNEst{
722-
// Number: 1235,
723-
// Float: 123.09,
724-
// },
725-
// },
726-
// },
727-
// expect: testNestedStruct{
728-
// Foo: "baz",
729-
// Bar: "quz",
730-
// Lol: testLol{
731-
// Bla: "booo",
732-
// Another: testAnotherNEst{
733-
// Number: 1235,
734-
// Float: 123.09,
735-
// },
736-
// },
737-
// },
738-
// cfmgr: func(t *testing.T) mockConfigManageriface {
739-
// mcm := &MockCfgMgr{}
740-
// mcm.retrieveInput = func(input string, config generator.GenVarsConfig) (string, error) {
741-
// return `{"foo":"baz","bar":"quz", "lol":{"bla":"booo","another":{"number": 1235, "float": 123.09}}}`, nil
742-
// }
743-
// return mcm
744-
// },
745-
// },
746-
// }
747-
// for _, tt := range tests {
748-
// t.Run(tt.name, func(t *testing.T) {
749-
// config := generator.NewConfig().WithTokenSeparator("://")
750-
// got, err := KubeControllerSpecHelper(tt.testType, tt.cfmgr(t), *config)
751-
// if err != nil {
752-
// t.Errorf(testutils.TestPhrase, err.Error(), nil)
753-
// }
754-
// if !reflect.DeepEqual(got, &tt.expect) {
755-
// t.Errorf(testutils.TestPhraseWithContext, "returned types do not deep equal", got, tt.expect)
756-
// }
757-
// })
758-
// }
759-
// }

internal/cmdutils/cmdutils.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ func (c *CmdUtils) GenerateStrOut(input io.Reader, inputOutputIsSame bool) error
7575
defer os.Remove(tempfile.Name())
7676
c.logger.Debug("tmp file created: %s", tempfile.Name())
7777
c.tempOutputWriter = tempfile
78-
// if err := c.setWriter(tempfile.Name()); err != nil {
79-
// return err
80-
// }
8178
defer c.tempOutputWriter.Close()
8279
return c.generateFromStrOutOverwrite(input, tempfile.Name())
8380
}
@@ -104,7 +101,6 @@ func (c *CmdUtils) generateFromStrOutOverwrite(input io.Reader, outtemp string)
104101
return err
105102
}
106103
return nil
107-
// return os.WriteFile(c.configManager.GeneratorConfig().OutputPath(), tr, 0644)
108104
}
109105

110106
// generateStrOutFromInput takes a reader and writer as input
@@ -114,6 +110,7 @@ func (c *CmdUtils) generateStrOutFromInput(input io.Reader, writer io.Writer) er
114110
if err != nil {
115111
return err
116112
}
113+
117114
str, err := c.configManager.RetrieveWithInputReplaced(string(b))
118115
if err != nil {
119116
return err

internal/cmdutils/cmdutils_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ func Test_GenerateStrOut(t *testing.T) {
165165
os.Remove(outputF.Name())
166166
}()
167167

168-
// inputReader, _ := cmdutils.GetReader(&cobra.Command{}, inputStr)
169-
// outputWriter, _ := cmdutils.GetWriter("stdout")
170-
171168
m := &mockCfgMgr{
172169
config: config.NewConfig(),
173170
parsedString: mockParsedStr,
@@ -185,7 +182,6 @@ func Test_GenerateStrOut(t *testing.T) {
185182
t.Run("succeeds input and output are set to the same file", func(t *testing.T) {
186183
inputF, _ := os.CreateTemp(os.TempDir(), "gen-conf-frrom-string*")
187184
inputF.Write([]byte(inputStr))
188-
// outputF, _ := os.CreateTemp(os.TempDir(), "gen-conf-frrom-string*")
189185
defer func() {
190186
os.Remove(inputF.Name())
191187
}()
@@ -206,20 +202,10 @@ func Test_GenerateStrOut(t *testing.T) {
206202

207203
func Test_CmdUtils_Errors_on(t *testing.T) {
208204
t.Run("outputFile wrong", func(t *testing.T) {
209-
// m := &mockCfgMgr{
210-
// config: config.NewConfig(),
211-
// parsedMap: generator.ParsedMap{"FOO://bar/qusx": "aksujg", "FOO://bar/lorem": "", "FOO://bar/ducks": "sdhbjk0293"},
212-
// }
213-
214-
// inputReader, _ := cmdutils.GetReader(&cobra.Command{}, inputStr)
215205
_, err := cmdutils.GetWriter("xunknown/file")
216206
if err == nil {
217207
t.Fatal("error not caught")
218208
}
219-
// cmd := cmdutils.New(m, log.New(&bytes.Buffer{}), outputWriter)
220-
// if err := cmd.GenerateFromCmd([]string{"IMNP://foo"}, "xunknown/file"); err == nil {
221-
// t.Errorf(testutils.TestPhraseWithContext, "file does not exist unable to create a writer", "err", nil)
222-
// }
223209
})
224210
t.Run("REtrieve from tokens in fetching ANY of the tokens", func(t *testing.T) {
225211
m := &mockCfgMgr{
@@ -271,7 +257,6 @@ func Test_CmdUtils_Errors_on(t *testing.T) {
271257
t.Run("REtrieve from string in fetching SOME of the tokens with input/output the same", func(t *testing.T) {
272258
inputF, _ := os.CreateTemp(os.TempDir(), "gen-conf-frrom-string*")
273259
inputF.Write([]byte(`"IMNP://foo", "IMNP://foo2"`))
274-
// outputF, _ := os.CreateTemp(os.TempDir(), "gen-conf-frrom-string*")
275260
defer func() {
276261
os.Remove(inputF.Name())
277262
}()

0 commit comments

Comments
 (0)