-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from bagutzu/helm-remove-oci-prefix
fix: remove oci prefix from helm url before adding it to helmfile.
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package helmfile_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/jenkins-x-plugins/jx-promote/pkg/jxtesthelpers" | ||
"github.com/jenkins-x-plugins/jx-promote/pkg/promoteconfig" | ||
"github.com/jenkins-x-plugins/jx-promote/pkg/rules" | ||
"github.com/jenkins-x-plugins/jx-promote/pkg/rules/helmfile" | ||
"github.com/jenkins-x/jx-helpers/v3/pkg/files" | ||
"github.com/jenkins-x/jx-helpers/v3/pkg/testhelpers" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRemoveOCISchemeFromHelmfileRepositoriesDuringDefaultPrefix(t *testing.T) { | ||
tmpDir, err := os.MkdirTemp("", "") | ||
require.NoError(t, err, "could not make a temp dir") | ||
|
||
t.Logf("creating tests at %s", tmpDir) | ||
|
||
sourceData := "test_data" | ||
fileSlice, err := os.ReadDir(sourceData) | ||
|
||
assert.NoError(t, err) | ||
|
||
ns := "jx" | ||
testPromoteNS := "jx" | ||
for _, f := range fileSlice { | ||
if !f.IsDir() { | ||
continue | ||
} | ||
name := f.Name() | ||
if name == "jenkins-x-versions" { | ||
continue | ||
} | ||
|
||
dir := filepath.Join(tmpDir, name) | ||
|
||
src := filepath.Join("test_data", name) | ||
err = files.CopyDirOverwrite(src, dir) | ||
require.NoError(t, err, "could not copy source data in %s to %s", src, dir) | ||
|
||
cfg, _, err := promoteconfig.Discover(dir, testPromoteNS) | ||
require.NoError(t, err, "failed to load cfg dir %s", dir) | ||
require.NotNil(t, cfg, "no project cfg found in dir %s", dir) | ||
|
||
envctx := jxtesthelpers.CreateTestDevEnvironmentContext(t, ns) | ||
envctx.Requirements.Cluster.ChartKind = "oci" | ||
|
||
r := &rules.PromoteRule{ | ||
TemplateContext: rules.TemplateContext{ | ||
GitURL: "https://github.com/myorg/myapp.git", | ||
Version: "1.2.3", | ||
AppName: "myapp", | ||
Namespace: ns, | ||
HelmRepositoryURL: "oci://chartmuseum-jx.34.78.195.22.nip.io", | ||
}, | ||
Dir: dir, | ||
Config: *cfg, | ||
DevEnvContext: envctx, | ||
} | ||
|
||
e := helmfile.Rule(r) | ||
require.Nil(t, e) | ||
testhelpers.AssertTextFilesEqual(t, filepath.Join(src, "helmfile.yaml.expected"), filepath.Join(dir, "helmfile.yaml"), "The OCI prefix has not been removed before adding it to the helmfile") | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
repositories: | ||
- name: yourorg | ||
url: https://yourorg.example.com/charts | ||
releases: | ||
- name: dbmigrator | ||
labels: | ||
job: dbmigrator | ||
chart: ./dbmigrator |
18 changes: 18 additions & 0 deletions
18
pkg/rules/helmfile/test_data/helmfile/helmfile.yaml.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
filepath: "" | ||
repositories: | ||
- name: yourorg | ||
url: https://yourorg.example.com/charts | ||
- name: dev | ||
url: chartmuseum-jx.34.78.195.22.nip.io | ||
oci: true | ||
releases: | ||
- chart: ./dbmigrator | ||
name: dbmigrator | ||
labels: | ||
job: dbmigrator | ||
- chart: dev/myapp | ||
version: 1.2.3 | ||
name: myapp | ||
namespace: jx | ||
templates: {} | ||
renderedvalues: {} |
4 changes: 4 additions & 0 deletions
4
pkg/rules/helmfile/test_data/jenkins-x-versions/packages/git.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: 2.15.0 | ||
upperLimit: 3.0.0 | ||
gitUrl: https://github.com/git/git.git | ||
url: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git |