mirror of https://github.com/helm/helm
Signed-off-by: Stephanie Hohenberg <stephanie.hohenberg@gmail.com>pull/31239/head
parent
90a91e097f
commit
8554a7fe4b
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
kubefake "helm.sh/helm/v4/pkg/kube/fake"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
func TestNewGet(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewGet(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
assert.Equal(t, 0, client.Version)
|
||||
}
|
||||
|
||||
func TestGetRun(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewGet(config)
|
||||
simpleRelease := namedReleaseStub("test-release", release.StatusPendingUpgrade)
|
||||
require.NoError(t, config.Releases.Create(simpleRelease))
|
||||
|
||||
result, err := client.Run(simpleRelease.Name)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, simpleRelease.Name, result.Name)
|
||||
assert.Equal(t, simpleRelease.Version, result.Version)
|
||||
}
|
||||
|
||||
func TestGetRun_UnreachableKubeClient(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.ConnectionError = errors.New("connection refused")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
client := NewGet(config)
|
||||
simpleRelease := namedReleaseStub("test-release", release.StatusPendingUpgrade)
|
||||
require.NoError(t, config.Releases.Create(simpleRelease))
|
||||
|
||||
result, err := client.Run(simpleRelease.Name)
|
||||
assert.Nil(t, result)
|
||||
assert.Error(t, err)
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
kubefake "helm.sh/helm/v4/pkg/kube/fake"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
func TestNewHistory(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewHistory(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestHistoryRun(t *testing.T) {
|
||||
releaseName := "test-release"
|
||||
simpleRelease := namedReleaseStub(releaseName, release.StatusPendingUpgrade)
|
||||
updatedRelease := namedReleaseStub(releaseName, release.StatusDeployed)
|
||||
updatedRelease.Chart.Metadata.Version = "0.1.1"
|
||||
updatedRelease.Version = 2
|
||||
|
||||
config := actionConfigFixture(t)
|
||||
client := NewHistory(config)
|
||||
client.Max = 3
|
||||
client.cfg.Releases.MaxHistory = 3
|
||||
for _, rel := range []*release.Release{simpleRelease, updatedRelease} {
|
||||
if err := client.cfg.Releases.Create(rel); err != nil {
|
||||
t.Fatal(err, "Could not add releases to Config")
|
||||
}
|
||||
}
|
||||
|
||||
releases, err := config.Releases.ListReleases()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, releases, 2, "expected 2 Releases in Config")
|
||||
|
||||
result, err := client.Run(releaseName)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, result, 2, "expected 2 Releases in History result")
|
||||
assert.Equal(t, simpleRelease.Name, result[0].Name)
|
||||
assert.Equal(t, simpleRelease.Version, result[0].Version)
|
||||
assert.Equal(t, updatedRelease.Name, result[1].Name)
|
||||
assert.Equal(t, updatedRelease.Version, result[1].Version)
|
||||
}
|
||||
|
||||
func TestHistoryRun_UnreachableKubeClient(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.ConnectionError = errors.New("connection refused")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
client := NewHistory(config)
|
||||
result, err := client.Run("release-name")
|
||||
assert.Nil(t, result)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestHistoryRun_InvalidReleaseNames(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewHistory(config)
|
||||
invalidReleaseNames := []string{
|
||||
"",
|
||||
"too-long-release-name-max-53-characters-abcdefghijklmnopqrstuvwxyz",
|
||||
"MyRelease",
|
||||
"release_name",
|
||||
"release@123",
|
||||
"-badstart",
|
||||
"badend-",
|
||||
".dotstart",
|
||||
}
|
||||
|
||||
for _, name := range invalidReleaseNames {
|
||||
result, err := client.Run(name)
|
||||
assert.Nil(t, result)
|
||||
assert.ErrorContains(t, err, "release name is invalid")
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"helm.sh/helm/v4/pkg/cli"
|
||||
"helm.sh/helm/v4/pkg/registry"
|
||||
)
|
||||
|
||||
func TestNewPull(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewPull(WithConfig(config))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestPullSetRegistryClient(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewPull(WithConfig(config))
|
||||
|
||||
registryClient := ®istry.Client{}
|
||||
client.SetRegistryClient(registryClient)
|
||||
assert.Equal(t, registryClient, client.cfg.RegistryClient)
|
||||
}
|
||||
|
||||
func TestPullRun_ChartNotFound(t *testing.T) {
|
||||
srv, err := startLocalServerForTests(t, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer srv.Close()
|
||||
|
||||
config := actionConfigFixture(t)
|
||||
client := NewPull(WithConfig(config))
|
||||
client.Settings = cli.New()
|
||||
client.RepoURL = srv.URL
|
||||
|
||||
chartRef := "nginx"
|
||||
_, err = client.Run(chartRef)
|
||||
require.ErrorContains(t, err, "404 Not Found")
|
||||
}
|
||||
|
||||
func startLocalServerForTests(t *testing.T, handler http.Handler) (*httptest.Server, error) {
|
||||
t.Helper()
|
||||
if handler == nil {
|
||||
fileBytes, err := os.ReadFile("../repo/v1/testdata/local-index.yaml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, err = w.Write(fileBytes)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
return httptest.NewServer(handler), nil
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewPushWithPushConfig(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewPushWithOpts(WithPushConfig(config))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestNewPushWithTLSClientConfig(t *testing.T) {
|
||||
certFile := "certFile"
|
||||
keyFile := "keyFile"
|
||||
caFile := "caFile"
|
||||
client := NewPushWithOpts(WithTLSClientConfig(certFile, keyFile, caFile))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, certFile, client.certFile)
|
||||
assert.Equal(t, keyFile, client.keyFile)
|
||||
assert.Equal(t, caFile, client.caFile)
|
||||
}
|
||||
|
||||
func TestNewPushWithInsecureSkipTLSVerify(t *testing.T) {
|
||||
client := NewPushWithOpts(WithInsecureSkipTLSVerify(true))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, true, client.insecureSkipTLSverify)
|
||||
}
|
||||
|
||||
func TestNewPushWithPlainHTTP(t *testing.T) {
|
||||
client := NewPushWithOpts(WithPlainHTTP(true))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, true, client.plainHTTP)
|
||||
}
|
||||
|
||||
func TestNewPushWithPushOptWriter(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
client := NewPushWithOpts(WithPushOptWriter(buf))
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, buf, client.out)
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRegistryLogin(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestWithCertFile(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
certFile := "testdata/cert.pem"
|
||||
opt := WithCertFile(certFile)
|
||||
|
||||
assert.Nil(t, opt(client))
|
||||
assert.Equal(t, certFile, client.certFile)
|
||||
}
|
||||
|
||||
func TestWithInsecure(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
opt := WithInsecure(true)
|
||||
|
||||
assert.Nil(t, opt(client))
|
||||
assert.Equal(t, true, client.insecure)
|
||||
}
|
||||
|
||||
func TestWithKeyFile(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
keyFile := "testdata/key.pem"
|
||||
opt := WithKeyFile(keyFile)
|
||||
|
||||
assert.Nil(t, opt(client))
|
||||
assert.Equal(t, keyFile, client.keyFile)
|
||||
}
|
||||
|
||||
func TestWithCAFile(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
caFile := "testdata/ca.pem"
|
||||
opt := WithCAFile(caFile)
|
||||
|
||||
assert.Nil(t, opt(client))
|
||||
assert.Equal(t, caFile, client.caFile)
|
||||
}
|
||||
|
||||
func TestWithPlainHTTPLogin(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogin(config)
|
||||
|
||||
opt := WithPlainHTTPLogin(true)
|
||||
|
||||
assert.Nil(t, opt(client))
|
||||
assert.Equal(t, true, client.plainHTTP)
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewRegistryLogout(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRegistryLogout(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"helm.sh/helm/v4/pkg/cli"
|
||||
kubefake "helm.sh/helm/v4/pkg/kube/fake"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
func TestNewReleaseTesting(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewReleaseTesting(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestReleaseTestingRun_UnreachableKubeClient(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.ConnectionError = errors.New("connection refused")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
client := NewReleaseTesting(config)
|
||||
result, err := client.Run("")
|
||||
assert.Nil(t, result)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestReleaseTestingGetPodLogs_FilterEvents(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
require.NoError(t, config.Init(cli.New().RESTClientGetter(), "", os.Getenv("HELM_DRIVER")))
|
||||
client := NewReleaseTesting(config)
|
||||
client.Filters[ExcludeNameFilter] = []string{"event-1"}
|
||||
client.Filters[IncludeNameFilter] = []string{"event-3"}
|
||||
|
||||
hooks := []*release.Hook{
|
||||
{
|
||||
Name: "event-1",
|
||||
Events: []release.HookEvent{release.HookTest},
|
||||
},
|
||||
{
|
||||
Name: "event-2",
|
||||
Events: []release.HookEvent{release.HookTest},
|
||||
},
|
||||
}
|
||||
|
||||
out := &bytes.Buffer{}
|
||||
require.NoError(t, client.GetPodLogs(out, &release.Release{Hooks: hooks}))
|
||||
|
||||
assert.Contains(t, "", out.String())
|
||||
}
|
||||
|
||||
func TestReleaseTestingGetPodLogs_PodRetrievalError(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
require.NoError(t, config.Init(cli.New().RESTClientGetter(), "", os.Getenv("HELM_DRIVER")))
|
||||
client := NewReleaseTesting(config)
|
||||
|
||||
hooks := []*release.Hook{
|
||||
{
|
||||
Name: "event-1",
|
||||
Events: []release.HookEvent{release.HookTest},
|
||||
},
|
||||
}
|
||||
|
||||
require.ErrorContains(t, client.GetPodLogs(&bytes.Buffer{}, &release.Release{Hooks: hooks}), "unable to get pod logs")
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
kubefake "helm.sh/helm/v4/pkg/kube/fake"
|
||||
)
|
||||
|
||||
func TestNewRollback(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewRollback(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
}
|
||||
|
||||
func TestRollbackRun_UnreachableKubeClient(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.ConnectionError = errors.New("connection refused")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
client := NewRollback(config)
|
||||
assert.Error(t, client.Run(""))
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
kubefake "helm.sh/helm/v4/pkg/kube/fake"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
)
|
||||
|
||||
func TestNewStatus(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
client := NewStatus(config)
|
||||
|
||||
assert.NotNil(t, client)
|
||||
assert.Equal(t, config, client.cfg)
|
||||
assert.Equal(t, 0, client.Version)
|
||||
}
|
||||
|
||||
func TestStatusRun(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.BuildDummy = true
|
||||
config.KubeClient = &failingKubeClient
|
||||
client := NewStatus(config)
|
||||
|
||||
releaseName := "test-release"
|
||||
require.NoError(t, configureReleaseContent(config, releaseName))
|
||||
result, err := client.Run(releaseName)
|
||||
client.ShowResourcesTable = true
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, releaseName, result.Name)
|
||||
assert.Equal(t, 1, result.Version)
|
||||
}
|
||||
|
||||
func TestStatusRun_KubeClientNotReachable(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.ConnectionError = errors.New("connection refused")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
client := NewStatus(config)
|
||||
|
||||
result, err := client.Run("")
|
||||
assert.Nil(t, result)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestStatusRun_KubeClientBuildTableError(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.BuildTableError = errors.New("build table error")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
releaseName := "test-release"
|
||||
require.NoError(t, configureReleaseContent(config, releaseName))
|
||||
|
||||
client := NewStatus(config)
|
||||
client.ShowResourcesTable = true
|
||||
|
||||
result, err := client.Run(releaseName)
|
||||
|
||||
assert.Nil(t, result)
|
||||
assert.ErrorContains(t, err, "build table error")
|
||||
}
|
||||
|
||||
func TestStatusRun_KubeClientBuildError(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.BuildError = errors.New("build error")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
releaseName := "test-release"
|
||||
require.NoError(t, configureReleaseContent(config, releaseName))
|
||||
|
||||
client := NewStatus(config)
|
||||
client.ShowResourcesTable = false
|
||||
|
||||
result, err := client.Run(releaseName)
|
||||
assert.Nil(t, result)
|
||||
assert.ErrorContains(t, err, "build error")
|
||||
}
|
||||
|
||||
func TestStatusRun_KubeClientGetError(t *testing.T) {
|
||||
config := actionConfigFixture(t)
|
||||
failingKubeClient := kubefake.FailingKubeClient{PrintingKubeClient: kubefake.PrintingKubeClient{Out: io.Discard}, DummyResources: nil}
|
||||
failingKubeClient.BuildError = errors.New("get error")
|
||||
config.KubeClient = &failingKubeClient
|
||||
|
||||
releaseName := "test-release"
|
||||
require.NoError(t, configureReleaseContent(config, releaseName))
|
||||
client := NewStatus(config)
|
||||
|
||||
result, err := client.Run(releaseName)
|
||||
assert.Nil(t, result)
|
||||
assert.ErrorContains(t, err, "get error")
|
||||
}
|
||||
|
||||
func configureReleaseContent(cfg *Configuration, releaseName string) error {
|
||||
rel := &release.Release{
|
||||
Name: releaseName,
|
||||
Info: &release.Info{
|
||||
Status: release.StatusDeployed,
|
||||
},
|
||||
Manifest: testManifest,
|
||||
Version: 1,
|
||||
Namespace: "default",
|
||||
}
|
||||
|
||||
return cfg.Releases.Create(rel)
|
||||
}
|
||||
|
||||
const testManifest = `
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
namespace: default
|
||||
name: test-application
|
||||
`
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright The Helm Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package action
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewVerify(t *testing.T) {
|
||||
client := NewVerify()
|
||||
|
||||
assert.NotNil(t, client)
|
||||
}
|
||||
|
||||
func TestVerifyRun(t *testing.T) {
|
||||
client := NewVerify()
|
||||
|
||||
client.Keyring = "../downloader/testdata/helm-test-key.pub"
|
||||
require.NoError(t, client.Run("../downloader/testdata/signtest-0.1.0.tgz"))
|
||||
}
|
||||
|
||||
func TestVerifyRun_DownloadError(t *testing.T) {
|
||||
client := NewVerify()
|
||||
require.Error(t, client.Run("invalid-chart-path"))
|
||||
}
|
Loading…
Reference in new issue