Skip to content

Commit

Permalink
Use main chart in tests (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyinbabal authored Oct 11, 2023
1 parent 5e6aed6 commit 82c612d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
3 changes: 1 addition & 2 deletions test/cloud-slack-dev-e2e/cloud_slack_dev_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ func TestCloudSlackE2E(t *testing.T) {
})

params := helmx.InstallChartParams{
// TODO(https://github.com/kubeshop/botkube/issues/1203): Update Helm chart version to the latest released one
RepoURL: "https://charts.botkube.io",
RepoURL: "https://storage.googleapis.com/botkube-latest-main-charts",
RepoName: "botkube",
Name: "botkube",
Namespace: "botkube",
Expand Down
30 changes: 27 additions & 3 deletions test/helmx/helm_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package helmx

import (
"encoding/json"
"os/exec"
"regexp"
"strings"
"testing"

Expand All @@ -17,10 +19,16 @@ type InstallChartParams struct {
Command string
}

type versionsResponse struct {
Version string `json:"version"`
}

// ToOptions converts Command to helm install options.
func (p *InstallChartParams) ToOptions() []string {
func (p *InstallChartParams) ToOptions(version string) []string {
cmd := strings.Replace(p.Command, "\n", "", -1)
cmd = strings.Replace(cmd, "\\", " ", -1)
versionRegex := regexp.MustCompile(`--version (\S+)`)
cmd = versionRegex.ReplaceAllString(cmd, "--version "+version)
return strings.Fields(cmd)[1:]
}

Expand All @@ -42,9 +50,17 @@ func InstallChart(t *testing.T, params InstallChartParams) func(t *testing.T) {
t.Log(string(repoUpdateOutput))
require.NoError(t, err)

t.Logf("Installing chart %s with command %s", params.Name, params.ToOptions())
t.Log("Finding latest version...")
cmd = exec.Command("helm", "search", "repo", params.RepoName, "--devel", "--versions", "-o", "json") // #nosec G204
versionsOutput, err := cmd.CombinedOutput()
require.NoError(t, err)
latestVersion := latestVersion(t, versionsOutput)
t.Logf("Found version: %s", latestVersion)

helmOpts := params.ToOptions(latestVersion)
t.Logf("Installing chart %s with command %s", params.Name, helmOpts)
//nolint:gosec // this is not production code
cmd = exec.Command("helm", params.ToOptions()...)
cmd = exec.Command("helm", helmOpts...)
installOutput, err := cmd.CombinedOutput()
t.Log(string(installOutput))
require.NoError(t, err)
Expand All @@ -59,3 +75,11 @@ func InstallChart(t *testing.T, params InstallChartParams) func(t *testing.T) {
require.NoError(t, err)
}
}

func latestVersion(t *testing.T, versionsOutput []byte) string {
var versions []versionsResponse
err := json.Unmarshal(versionsOutput, &versions)
require.NoError(t, err)
require.NotEmpty(t, versions)
return versions[0].Version
}

0 comments on commit 82c612d

Please sign in to comment.