Skip to content

Commit

Permalink
tests(kumactl) tests for kumactl install logging
Browse files Browse the repository at this point in the history
  • Loading branch information
xbauquet committed Jun 18, 2020
1 parent 5774465 commit d0561cc
Show file tree
Hide file tree
Showing 8 changed files with 1,515 additions and 2 deletions.
31 changes: 31 additions & 0 deletions app/kumactl/cmd/completion/testdata/bash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,36 @@ _kumactl_install_ingress()
noun_aliases=()
}

_kumactl_install_logging()
{
last_command="kumactl_install_logging"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--namespace=")
two_word_flags+=("--namespace")
local_nonpersistent_flags+=("--namespace=")
flags+=("--config-file=")
two_word_flags+=("--config-file")
flags+=("--log-level=")
two_word_flags+=("--log-level")
flags+=("--mesh=")
two_word_flags+=("--mesh")
two_word_flags+=("-m")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_kumactl_install_metrics()
{
last_command="kumactl_install_metrics"
Expand Down Expand Up @@ -1857,6 +1887,7 @@ _kumactl_install()
commands+=("control-plane")
commands+=("dns")
commands+=("ingress")
commands+=("logging")
commands+=("metrics")
commands+=("tracing")

Expand Down
12 changes: 12 additions & 0 deletions app/kumactl/cmd/completion/testdata/zsh.golden
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ function _kumactl_install {
"control-plane:Install Kuma Control Plane on Kubernetes"
"dns:Install DNS to Kubernetes"
"ingress:Install Ingress on Kubernetes"
"logging:Install Logging backend in Kubernetes cluster (Loki)"
"metrics:Install Metrics backend in Kubernetes cluster (Prometheus + Grafana)"
"tracing:Install Tracing backend in Kubernetes cluster (Jaeger)"
)
Expand All @@ -686,6 +687,9 @@ function _kumactl_install {
ingress)
_kumactl_install_ingress
;;
logging)
_kumactl_install_logging
;;
metrics)
_kumactl_install_metrics
;;
Expand Down Expand Up @@ -738,6 +742,14 @@ function _kumactl_install_ingress {
'(-m --mesh)'{-m,--mesh}'[mesh to use]:'
}

function _kumactl_install_logging {
_arguments \
'--namespace[namespace to install logging to]:' \
'--config-file[path to the configuration file to use]:' \
'--log-level[log level: one of off|info|debug]:' \
'(-m --mesh)'{-m,--mesh}'[mesh to use]:'
}

function _kumactl_install_metrics {
_arguments \
'--kuma-cp-address[the address of Kuma CP]:' \
Expand Down
89 changes: 89 additions & 0 deletions app/kumactl/cmd/install/install_logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package install_test

import (
"bytes"
"io/ioutil"
"path/filepath"

kuma_version "github.com/Kong/kuma/pkg/version"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

"github.com/Kong/kuma/app/kumactl/cmd"
"github.com/Kong/kuma/app/kumactl/pkg/install/data"
)

var _ = Describe("kumactl install logging", func() {

var stdout *bytes.Buffer
var stderr *bytes.Buffer

BeforeEach(func() {
stdout = &bytes.Buffer{}
stderr = &bytes.Buffer{}
})

type testCase struct {
extraArgs []string
goldenFile string
}

BeforeEach(func() {
kuma_version.Build = kuma_version.BuildInfo{
Version: "0.0.1",
GitTag: "v0.0.1",
GitCommit: "91ce236824a9d875601679aa80c63783fb0e8725",
BuildDate: "2019-08-07T11:26:06Z",
}
})

DescribeTable("should generate Kubernetes resources",
func(given testCase) {
// given
rootCmd := cmd.DefaultRootCmd()
rootCmd.SetArgs(append([]string{"install", "logging"}, given.extraArgs...))
rootCmd.SetOut(stdout)
rootCmd.SetErr(stderr)

// when
err := rootCmd.Execute()
// then
Expect(err).ToNot(HaveOccurred())
// and
Expect(stderr.Bytes()).To(BeNil())

// when
expected, err := ioutil.ReadFile(filepath.Join("testdata", given.goldenFile))
// then
Expect(err).ToNot(HaveOccurred())
// and
expectedManifests := data.SplitYAML(data.File{Data: expected})

// when
actual := stdout.Bytes()
// then
Expect(actual).To(MatchYAML(expected))
// and
actualManifests := data.SplitYAML(data.File{Data: actual})

// and
Expect(len(actualManifests)).To(Equal(len(expectedManifests)))
// and
for i := range expectedManifests {
Expect(actualManifests[i]).To(MatchYAML(expectedManifests[i]))
}
},
Entry("should generate Kubernetes resources with default settings", testCase{
extraArgs: nil,
goldenFile: "install-logging.defaults.golden.yaml",
}),
Entry("should generate Kubernetes resources with custom settings", testCase{
extraArgs: []string{
"--namespace", "kuma",
},
goldenFile: "install-logging.overrides.golden.yaml",
}),
)
})
Loading

0 comments on commit d0561cc

Please sign in to comment.