diff --git a/functions/download/BUILD.bazel b/functions/download/BUILD.bazel index 92ad20c..2cd4a04 100644 --- a/functions/download/BUILD.bazel +++ b/functions/download/BUILD.bazel @@ -20,6 +20,8 @@ go_test( embed = [":download"], deps = [ "//functions/base", + "//libraries/logging", + "@com_github_google_deck//:deck", "@com_github_spf13_afero//:afero", "@com_github_stretchr_testify//assert", "@net_starlark_go//starlark", diff --git a/functions/download/download_test.go b/functions/download/download_test.go index 98ff27e..8ce91c1 100644 --- a/functions/download/download_test.go +++ b/functions/download/download_test.go @@ -9,6 +9,8 @@ import ( "testing" "github.com/discentem/starcm/functions/base" + "github.com/discentem/starcm/libraries/logging" + "github.com/google/deck" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "go.starlark.net/starlark" @@ -78,9 +80,11 @@ func TestRun(t *testing.T) { }, }, expectedResult: func(result *base.Result) bool { + logging.Log("result", deck.V(1), "result", "result: %v", result) return result != nil }, expectedError: func(err error) bool { + logging.Log("result", deck.V(1), "error", "error: %v", err) return err == nil }, }, diff --git a/functions/shell/shell.go b/functions/shell/shell.go index 2223d20..21d6360 100644 --- a/functions/shell/shell.go +++ b/functions/shell/shell.go @@ -21,27 +21,22 @@ type shellAction struct { func (a *shellAction) Run(ctx context.Context, workingDirectory string, moduleName string, args starlark.Tuple, kwargs []starlark.Tuple) (*base.Result, error) { - idx, err := starlarkhelpers.FindIndexOfValueInKwargs(kwargs, "cmd") - if err != nil { - return nil, err - } - if idx == starlarkhelpers.IndexNotFound { + cmd, err := starlarkhelpers.FindValueinKwargs(kwargs, "cmd") + if cmd == nil { return nil, fmt.Errorf("'cmd' was not found in kwargs") } - - c, _, _, err := starlarkhelpers.Unquote(kwargs[idx][1].String()) - if err != nil { - return nil, err + if cmd == nil { + return nil, fmt.Errorf("'cmd' was nil") } - idx, err = starlarkhelpers.FindIndexOfValueInKwargs(kwargs, "args") + cargs, err := starlarkhelpers.FindRawValueInKwargs(kwargs, "args") if err != nil { return nil, err } - if idx == starlarkhelpers.IndexNotFound { - return nil, fmt.Errorf("'args' was not found in kwargs") + cargsList, ok := cargs.(*starlark.List) + if !ok { + return nil, fmt.Errorf("'args' was not a list") } - cargs := (kwargs[idx][1]).(*starlark.List) expectedExitCode, err := starlarkhelpers.FindIntInKwargs(kwargs, "expected_exit_code", 0) if err != nil { @@ -53,7 +48,7 @@ func (a *shellAction) Run(ctx context.Context, workingDirectory string, moduleNa return nil, err } - iter := cargs.Iterate() + iter := cargsList.Iterate() defer iter.Done() var v starlark.Value var cmdArgsGo []string @@ -62,7 +57,7 @@ func (a *shellAction) Run(ctx context.Context, workingDirectory string, moduleNa } ex := &shelllib.RealExecutor{} - ex.Command(c, cmdArgsGo...) + ex.Command(*cmd, cmdArgsGo...) buff := bytes.NewBuffer(nil) wc := shelllib.NopBufferCloser{ diff --git a/functions/template/template.go b/functions/template/template.go index 11328fc..92f1bef 100644 --- a/functions/template/template.go +++ b/functions/template/template.go @@ -20,16 +20,17 @@ import ( "go.starlark.net/starlark" ) -type templateAction struct { - fsys afero.Fs -} - type writeTemplateOptions struct { persist bool } -func (a *templateAction) writeTemplate(path string, data []byte, opts writeTemplateOptions) error { - if !opts.persist { +type templateAction struct { + fsys afero.Fs + options writeTemplateOptions +} + +func (a *templateAction) writeTemplate(path string, data []byte) error { + if !a.options.persist { logging.Log("template", deck.V(2), "info", "skipping write to disk because persist is false") return nil } @@ -184,9 +185,6 @@ func (a *templateAction) Run(ctx context.Context, workingDirectory string, modul if err := a.writeTemplate( destinationPath, []byte(renderedTemplate), - writeTemplateOptions{ - persist: !whatIf, - }, ); err != nil { return &base.Result{ Name: &moduleName, @@ -231,9 +229,6 @@ func (a *templateAction) Run(ctx context.Context, workingDirectory string, modul if err := a.writeTemplate( destinationPath, []byte(renderedTemplate), - writeTemplateOptions{ - persist: !whatIf, - }, ); err != nil { return &base.Result{ Name: &moduleName, diff --git a/functions/template/template_test.go b/functions/template/template_test.go index ebe797d..92b9328 100644 --- a/functions/template/template_test.go +++ b/functions/template/template_test.go @@ -156,13 +156,16 @@ func TestTemplateAction_writeTemplate(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { fs := tt.setupFs() - action := &templateAction{fsys: fs} + action := &templateAction{ + fsys: fs, + options: writeTemplateOptions{ + persist: true, + }, + } err := action.writeTemplate( tt.destinationPath, tt.finalContent, - writeTemplateOptions{ - persist: true, - }) + ) if tt.wantErr { assert.Error(t, err)