Initialize Steps with a NewSTEPNAME function [#67]
This seems to be be a more natural separation of concerns--the knowledge of which config fields map to which parts of a Step belong to the Step, not to the Plan.
This commit is contained in:
@@ -11,6 +11,13 @@ type AddRepo struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewAddRepo creates an AddRepo for the given repo-spec. No validation is performed at this time.
|
||||
func NewAddRepo(repo string) *AddRepo {
|
||||
return &AddRepo{
|
||||
Repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm repo add` command.
|
||||
func (a *AddRepo) Execute(_ Config) error {
|
||||
return a.cmd.Run()
|
||||
|
||||
@@ -38,6 +38,12 @@ func TestAddRepoTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(AddRepoTestSuite))
|
||||
}
|
||||
|
||||
func (suite *AddRepoTestSuite) TestNewAddRepo() {
|
||||
repo := NewAddRepo("picompress=https://github.com/caleb_phipps/picompress")
|
||||
suite.Require().NotNil(repo)
|
||||
suite.Equal("picompress=https://github.com/caleb_phipps/picompress", repo.Repo)
|
||||
}
|
||||
|
||||
func (suite *AddRepoTestSuite) TestPrepareAndExecute() {
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
|
||||
@@ -2,6 +2,7 @@ package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
)
|
||||
|
||||
// DepUpdate is an execution step that calls `helm dependency update` when executed.
|
||||
@@ -10,6 +11,13 @@ type DepUpdate struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewDepUpdate creates a DepUpdate using fields from the given Config. No validation is performed at this time.
|
||||
func NewDepUpdate(cfg env.Config) *DepUpdate {
|
||||
return &DepUpdate{
|
||||
Chart: cfg.Chart,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm upgrade` command.
|
||||
func (d *DepUpdate) Execute(_ Config) error {
|
||||
return d.cmd.Run()
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -31,6 +32,14 @@ func TestDepUpdateTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(DepUpdateTestSuite))
|
||||
}
|
||||
|
||||
func (suite *DepUpdateTestSuite) TestNewDepUpdate() {
|
||||
cfg := env.Config{
|
||||
Chart: "scatterplot",
|
||||
}
|
||||
d := NewDepUpdate(cfg)
|
||||
suite.Equal("scatterplot", d.Chart)
|
||||
}
|
||||
|
||||
func (suite *DepUpdateTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
)
|
||||
|
||||
// Help is a step in a helm Plan that calls `helm help`.
|
||||
@@ -10,6 +11,13 @@ type Help struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewHelp creates a Help using fields from the given Config. No validation is performed at this time.
|
||||
func NewHelp(cfg env.Config) *Help {
|
||||
return &Help{
|
||||
HelmCommand: cfg.Command,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm help` command.
|
||||
func (h *Help) Execute(cfg Config) error {
|
||||
if err := h.cmd.Run(); err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
@@ -17,6 +18,15 @@ func TestHelpTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(HelpTestSuite))
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestNewHelp() {
|
||||
cfg := env.Config{
|
||||
Command: "everybody dance NOW!!",
|
||||
}
|
||||
help := NewHelp(cfg)
|
||||
suite.Require().NotNil(help)
|
||||
suite.Equal("everybody dance NOW!!", help.HelmCommand)
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepare() {
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
defer ctrl.Finish()
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"io"
|
||||
"os"
|
||||
"text/template"
|
||||
@@ -32,6 +33,19 @@ type kubeValues struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
// NewInitKube creates a InitKube using the given Config and filepaths. No validation is performed at this time.
|
||||
func NewInitKube(cfg env.Config, templateFile, configFile string) *InitKube {
|
||||
return &InitKube{
|
||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
||||
Certificate: cfg.Certificate,
|
||||
APIServer: cfg.APIServer,
|
||||
ServiceAccount: cfg.ServiceAccount,
|
||||
Token: cfg.KubeToken,
|
||||
TemplateFile: templateFile,
|
||||
ConfigFile: configFile,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute generates a kubernetes config file from drone-helm3's template.
|
||||
func (i *InitKube) Execute(cfg Config) error {
|
||||
if cfg.Debug {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/suite"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
@@ -17,6 +18,27 @@ func TestInitKubeTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(InitKubeTestSuite))
|
||||
}
|
||||
|
||||
func (suite *InitKubeTestSuite) TestNewInitKube() {
|
||||
cfg := env.Config{
|
||||
SkipTLSVerify: true,
|
||||
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
||||
APIServer: "98.765.43.21",
|
||||
ServiceAccount: "greathelm",
|
||||
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
||||
}
|
||||
|
||||
init := NewInitKube(cfg, "conf.tpl", "conf.yml")
|
||||
suite.Equal(&InitKube{
|
||||
SkipTLSVerify: true,
|
||||
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
||||
APIServer: "98.765.43.21",
|
||||
ServiceAccount: "greathelm",
|
||||
Token: "b2YgbXkgYWZmZWN0aW9u",
|
||||
TemplateFile: "conf.tpl",
|
||||
ConfigFile: "conf.yml",
|
||||
}, init)
|
||||
}
|
||||
|
||||
func (suite *InitKubeTestSuite) TestPrepareExecute() {
|
||||
templateFile, err := tempfile("kubeconfig********.yml.tpl", `
|
||||
certificate: {{ .Certificate }}
|
||||
|
||||
@@ -2,6 +2,7 @@ package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
)
|
||||
|
||||
// Lint is an execution step that calls `helm lint` when executed.
|
||||
@@ -14,6 +15,17 @@ type Lint struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewLint creates a Lint using fields from the given Config. No validation is performed at this time.
|
||||
func NewLint(cfg env.Config) *Lint {
|
||||
return &Lint{
|
||||
Chart: cfg.Chart,
|
||||
Values: cfg.Values,
|
||||
StringValues: cfg.StringValues,
|
||||
ValuesFiles: cfg.ValuesFiles,
|
||||
Strict: cfg.LintStrictly,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm lint` command.
|
||||
func (l *Lint) Execute(_ Config) error {
|
||||
return l.cmd.Run()
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -31,6 +32,25 @@ func TestLintTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(LintTestSuite))
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestNewLint() {
|
||||
cfg := env.Config{
|
||||
Chart: "./flow",
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
LintStrictly: true,
|
||||
}
|
||||
lint := NewLint(cfg)
|
||||
suite.Require().NotNil(lint)
|
||||
suite.Equal(&Lint{
|
||||
Chart: "./flow",
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
Strict: true,
|
||||
}, lint)
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
)
|
||||
|
||||
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
||||
@@ -12,6 +13,15 @@ type Uninstall struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewUninstall creates an Uninstall using fields from the given Config. No validation is performed at this time.
|
||||
func NewUninstall(cfg env.Config) *Uninstall {
|
||||
return &Uninstall{
|
||||
Release: cfg.Release,
|
||||
DryRun: cfg.DryRun,
|
||||
KeepHistory: cfg.KeepHistory,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm uninstall` command.
|
||||
func (u *Uninstall) Execute(_ Config) error {
|
||||
return u.cmd.Run()
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -35,6 +36,20 @@ func TestUninstallTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(UninstallTestSuite))
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestNewUninstall() {
|
||||
cfg := env.Config{
|
||||
DryRun: true,
|
||||
Release: "jetta_id_love_to_change_the_world",
|
||||
KeepHistory: true,
|
||||
}
|
||||
u := NewUninstall(cfg)
|
||||
suite.Equal(&Uninstall{
|
||||
Release: "jetta_id_love_to_change_the_world",
|
||||
DryRun: true,
|
||||
KeepHistory: true,
|
||||
}, u)
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
)
|
||||
|
||||
// Upgrade is an execution step that calls `helm upgrade` when executed.
|
||||
@@ -24,6 +25,25 @@ type Upgrade struct {
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// NewUpgrade creates an Upgrade using fields from the given Config. No validation is performed at this time.
|
||||
func NewUpgrade(cfg env.Config) *Upgrade {
|
||||
return &Upgrade{
|
||||
Chart: cfg.Chart,
|
||||
Release: cfg.Release,
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: cfg.DryRun,
|
||||
Wait: cfg.Wait,
|
||||
Values: cfg.Values,
|
||||
StringValues: cfg.StringValues,
|
||||
ValuesFiles: cfg.ValuesFiles,
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
Force: cfg.Force,
|
||||
Atomic: cfg.AtomicUpgrade,
|
||||
CleanupOnFail: cfg.CleanupOnFail,
|
||||
}
|
||||
}
|
||||
|
||||
// Execute executes the `helm upgrade` command.
|
||||
func (u *Upgrade) Execute(_ Config) error {
|
||||
return u.cmd.Run()
|
||||
|
||||
@@ -3,6 +3,7 @@ package run
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pelotech/drone-helm3/internal/env"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -31,6 +32,41 @@ func TestUpgradeTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(UpgradeTestSuite))
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestNewUpgrade() {
|
||||
cfg := env.Config{
|
||||
ChartVersion: "seventeen",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
ReuseValues: true,
|
||||
Timeout: "go sit in the corner",
|
||||
Chart: "billboard_top_100",
|
||||
Release: "post_malone_circles",
|
||||
Force: true,
|
||||
AtomicUpgrade: true,
|
||||
CleanupOnFail: true,
|
||||
}
|
||||
|
||||
up := NewUpgrade(cfg)
|
||||
suite.Equal(&Upgrade{
|
||||
Chart: cfg.Chart,
|
||||
Release: cfg.Release,
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: true,
|
||||
Wait: cfg.Wait,
|
||||
Values: "steadfastness,forthrightness",
|
||||
StringValues: "tensile_strength,flexibility",
|
||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
Force: cfg.Force,
|
||||
Atomic: true,
|
||||
CleanupOnFail: true,
|
||||
}, up)
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user