Skip to content

Commit

Permalink
Test InitKube's use of the Debug flag [#67]
Browse files Browse the repository at this point in the history
(Just something I happened across while writing the previous commit)
  • Loading branch information
ErinCall committed Jan 16, 2020
1 parent 2311385 commit d8ddb79
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/run/initkube_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run

import (
"fmt"
"github.com/pelotech/drone-helm3/internal/env"
"github.com/stretchr/testify/suite"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -251,6 +252,40 @@ func (suite *InitKubeTestSuite) TestPrepareDefaultsServiceAccount() {
suite.Equal("helm", init.values.ServiceAccount)
}

func (suite *InitKubeTestSuite) TestDebugOutput() {
templateFile, err := tempfile("kubeconfig********.yml.tpl", "hurgity burgity")
defer os.Remove(templateFile.Name())
suite.Require().Nil(err)

configFile, err := tempfile("kubeconfig********.yml", "")
defer os.Remove(configFile.Name())
suite.Require().Nil(err)

stdout := &strings.Builder{}
stderr := &strings.Builder{}
cfg := env.Config{
APIServer: "http://my.kube.server/",
KubeToken: "QSBzaW5nbGUgcm9zZQ==",
Debug: true,
Stdout: stdout,
Stderr: stderr,
}
runCfg := Config{
Debug: true,
Stdout: stdout,
Stderr: stderr,
}

init := NewInitKube(cfg, templateFile.Name(), configFile.Name())
suite.NoError(init.Prepare(runCfg))

suite.Contains(stderr.String(), fmt.Sprintf("loading kubeconfig template from %s\n", templateFile.Name()))
suite.Contains(stderr.String(), fmt.Sprintf("truncating kubeconfig file at %s\n", configFile.Name()))

suite.NoError(init.Execute())
suite.Contains(stderr.String(), fmt.Sprintf("writing kubeconfig file to %s\n", configFile.Name()))
}

func tempfile(name, contents string) (*os.File, error) {
file, err := ioutil.TempFile("", name)
if err != nil {
Expand Down

0 comments on commit d8ddb79

Please sign in to comment.