Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions functions/download/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions functions/download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
},
},
Expand Down
25 changes: 10 additions & 15 deletions functions/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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{
Expand Down
19 changes: 7 additions & 12 deletions functions/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions functions/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down