Actual drone-invokable helm commands

This commit is contained in:
Erin Call
2019-12-05 14:35:25 -08:00
parent e77f6842b9
commit 238ede6f9e
11 changed files with 130 additions and 53 deletions

View File

@@ -7,6 +7,8 @@ import (
"syscall"
)
const HELM_BIN = "/usr/bin/helm"
// The cmd interface provides a generic form of exec.Cmd so that it can be mocked out in tests.
type cmd interface {
// methods that exist on exec.Cmd
@@ -41,8 +43,10 @@ type execCmd struct {
*exec.Cmd
}
var Command = func() cmd {
return &execCmd{}
var Command = func(path string, args ...string) cmd {
return &execCmd{
Cmd: exec.Command(path, args...),
}
}
func (c *execCmd) Path(p string) { c.Cmd.Path = p }

15
internal/run/help.go Normal file
View File

@@ -0,0 +1,15 @@
package run
import (
"os"
)
func Help(args ...string) error {
args = append([]string{"help"}, args...)
cmd := Command(HELM_BIN, args...)
cmd.Stdout(os.Stdout)
cmd.Stderr(os.Stderr)
return cmd.Run()
}

32
internal/run/help_test.go Normal file
View File

@@ -0,0 +1,32 @@
package run
import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestHelp(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mCmd := NewMockcmd(ctrl)
originalCommand := Command
Command = func(path string, args ...string) cmd {
assert.Equal(t, HELM_BIN, path)
assert.Equal(t, []string{"help", "arg1", "arg2"}, args)
return mCmd
}
defer func() { Command = originalCommand }()
mCmd.EXPECT().
Stdout(gomock.Any())
mCmd.EXPECT().
Stderr(gomock.Any())
mCmd.EXPECT().
Run().
Times(1)
Help("arg1", "arg2")
}

View File

@@ -1,15 +0,0 @@
package run
import ()
const HELM_BIN = "/usr/bin/helm"
func Install(args ...string) error {
cmd := Command()
cmd.Path(HELM_BIN)
args = append([]string{"install"}, args...)
cmd.Args(args)
return cmd.Run()
}

View File

@@ -1,26 +0,0 @@
package run
import (
"github.com/golang/mock/gomock"
"testing"
)
func TestInstall(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mCmd := NewMockcmd(ctrl)
originalCommand := Command
Command = func() cmd { return mCmd }
defer func() { Command = originalCommand }()
mCmd.EXPECT().
Path(HELM_BIN)
mCmd.EXPECT().
Args(gomock.Eq([]string{"install", "arg1", "arg2"}))
mCmd.EXPECT().
Run().
Times(1)
Install("arg1", "arg2")
}

15
internal/run/upgrade.go Normal file
View File

@@ -0,0 +1,15 @@
package run
import (
"os"
)
func Upgrade(args ...string) error {
args = append([]string{"upgrade"}, args...)
cmd := Command(HELM_BIN, args...)
cmd.Stdout(os.Stdout)
cmd.Stderr(os.Stderr)
return cmd.Run()
}

View File

@@ -0,0 +1,33 @@
package run
import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestUpgrade(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mCmd := NewMockcmd(ctrl)
originalCommand := Command
Command = func(path string, args ...string) cmd {
assert.Equal(t, HELM_BIN, path)
assert.Equal(t, []string{"upgrade", "arg1", "arg2"}, args)
return mCmd
}
defer func() { Command = originalCommand }()
mCmd.EXPECT().
Stdout(gomock.Any())
mCmd.EXPECT().
Stderr(gomock.Any())
mCmd.EXPECT().
Run().
Times(1)
Upgrade("arg1", "arg2")
}