Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Orive Oneca <[email protected]>
  • Loading branch information
Adirio committed Feb 24, 2021
1 parent 7ea0e35 commit 4ae7fc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ var _ = Describe("Running a generate packagemanifests command", func() {
err := c.setDefaults()
Expect(err).NotTo(HaveOccurred())
Expect(c.packageName).To(Equal("memcached-operator"))
Expect(c.layout).To(Equal("go.kubebuilder.io/v3"))
Expect(c.layout).To(Equal("go.kubebuilder.io/v3,manifests.sdk.operatorframework.io/v1,scorecard.sdk.operatorframework.io/v1"))
})
It("doesn't overwrite the package name if it's already set", func() {
c.packageName = "cherry"

err := c.setDefaults()
Expect(err).NotTo(HaveOccurred())
Expect(c.packageName).To(Equal("cherry"))
Expect(c.layout).To(Equal("go.kubebuilder.io/v3"))
Expect(c.layout).To(Equal("go.kubebuilder.io/v3,manifests.sdk.operatorframework.io/v1,scorecard.sdk.operatorframework.io/v1"))
})
})
Context("an invalid project file is present", func() {
Expand Down
33 changes: 3 additions & 30 deletions internal/plugins/helm/v1/chartutil/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/stretchr/testify/assert"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/repo/repotest"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"

"github.com/operator-framework/operator-sdk/internal/plugins/helm/v1/chartutil"
)
Expand All @@ -49,7 +48,6 @@ func TestCreateChart(t *testing.T) {
customVersion = "v1"
customKind = "MyApp"
customExpectName = "myapp"
expectDerivedKind = "TestChart"
)

testCases := []createChartTestCase{
Expand Down Expand Up @@ -82,35 +80,30 @@ func TestCreateChart(t *testing.T) {
group: customGroup,
version: customVersion,
kind: customKind,
expectResource: mustNewResource(customGroup, customVersion, customKind),
expectChartName: customExpectName,
expectChartVersion: "0.1.0",
},
{
name: "from directory",
helmChart: filepath.Join(".", "testdata", chartName),
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from archive",
helmChart: filepath.Join(".", "testdata", fmt.Sprintf("%s-%s.tgz", chartName, latestVersion)),
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from url",
helmChart: fmt.Sprintf("%s/%s-%s.tgz", srv.URL(), chartName, latestVersion),
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from repo and name implicit latest",
helmChart: "test/" + chartName,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand All @@ -119,15 +112,13 @@ func TestCreateChart(t *testing.T) {
helmChart: "test/" + chartName,
group: customGroup,
version: customVersion,
expectResource: mustNewResource(customGroup, customVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from repo and name implicit latest with kind",
helmChart: "test/" + chartName,
kind: customKind,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, customKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand All @@ -137,31 +128,27 @@ func TestCreateChart(t *testing.T) {
group: customGroup,
version: customVersion,
kind: customKind,
expectResource: mustNewResource(customGroup, customVersion, customKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from repo and name explicit latest",
helmChart: "test/" + chartName,
helmChartVersion: latestVersion,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
{
name: "from repo and name explicit previous",
helmChart: "test/" + chartName,
helmChartVersion: previousVersion,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: previousVersion,
},
{
name: "from name and repo url implicit latest",
helmChart: chartName,
helmChartRepo: srv.URL(),
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand All @@ -170,7 +157,6 @@ func TestCreateChart(t *testing.T) {
helmChart: chartName,
helmChartRepo: srv.URL(),
helmChartVersion: latestVersion,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: latestVersion,
},
Expand All @@ -179,7 +165,6 @@ func TestCreateChart(t *testing.T) {
helmChart: chartName,
helmChartRepo: srv.URL(),
helmChartVersion: previousVersion,
expectResource: mustNewResource(chartutil.DefaultGroup, chartutil.DefaultVersion, expectDerivedKind),
expectChartName: chartName,
expectChartVersion: previousVersion,
},
Expand All @@ -202,22 +187,11 @@ type createChartTestCase struct {
helmChartVersion string
helmChartRepo string

expectResource *golang.Options
expectChartName string
expectChartVersion string
expectErr bool
}

func mustNewResource(group, version, kind string) *golang.Options {
r := &golang.Options{
Namespaced: true,
Group: group,
Version: version,
Kind: kind,
}
return r
}

func runTestCase(t *testing.T, testDir string, tc createChartTestCase) {
outputDir := filepath.Join(testDir, "output")
assert.NoError(t, os.Mkdir(outputDir, 0755))
Expand All @@ -233,7 +207,7 @@ func runTestCase(t *testing.T, testDir string, tc createChartTestCase) {
defer os.Unsetenv("HELM_REPOSITORY_CACHE")

opts := chartutil.CreateOptions{
GVK: schema.GroupVersionKind{
GVK: resource.GVK{
Group: tc.group,
Version: tc.version,
Kind: tc.kind,
Expand All @@ -242,7 +216,7 @@ func runTestCase(t *testing.T, testDir string, tc createChartTestCase) {
Version: tc.helmChartVersion,
Repo: tc.helmChartRepo,
}
resource, chrt, err := chartutil.CreateChart(outputDir, opts)
chrt, err := chartutil.CreateChart(outputDir, opts)
if tc.expectErr {
assert.Error(t, err)
return
Expand All @@ -251,7 +225,6 @@ func runTestCase(t *testing.T, testDir string, tc createChartTestCase) {
if !assert.NoError(t, err) {
return
}
assert.Equal(t, tc.expectResource, resource)
assert.Equal(t, tc.expectChartName, chrt.Name())
assert.Equal(t, tc.expectChartVersion, chrt.Metadata.Version)

Expand Down

0 comments on commit 4ae7fc6

Please sign in to comment.