Skip to content

Commit e4398d1

Browse files
authored
Merge pull request #61 from puzzle/add-test
Add test for existing chart check
2 parents 5aade16 + 5fa3afa commit e4398d1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"dagger/go/internal/dagger"
66
"fmt"
7+
"time"
78

89
"github.com/sourcegraph/conc/pool"
910
)
@@ -21,6 +22,7 @@ func (m *Go) All(ctx context.Context) error {
2122
p.Go(m.HelmLintWithArgs)
2223
p.Go(m.HelmLintWithMissingDependencies)
2324
p.Go(m.HelmPackagePush)
25+
p.Go(m.HelmPackagePushWithExistingChart)
2426

2527
return p.Wait()
2628
}
@@ -83,6 +85,44 @@ func (m *Go) HelmPackagePush(
8385
return nil
8486
}
8587

88+
func (m *Go) HelmPackagePushWithExistingChart(
89+
// method call context
90+
ctx context.Context,
91+
) error {
92+
// directory that contains the Helm Chart
93+
directory := dag.CurrentModule().Source().Directory("./testdata/mychart/")
94+
randomString := fmt.Sprintf("%d", time.Now().UnixNano())
95+
// set name and version to arbitrary values
96+
directory = directory.
97+
WithoutFile("Chart.yaml").
98+
WithNewFile("Chart.yaml",
99+
fmt.Sprintf(`
100+
apiVersion: v2
101+
name: dagger-module-helm-test-%s
102+
description: A Helm chart
103+
type: application
104+
version: 0.1.%s
105+
`, randomString, randomString))
106+
107+
returnValue, err := dag.Helm().PackagePush(ctx, directory, "ttl.sh", "helm", "username", dag.SetSecret("password", "secret"))
108+
if err != nil {
109+
return err
110+
}
111+
if !returnValue {
112+
return fmt.Errorf("should return true because chart does not exists")
113+
}
114+
115+
returnValue, err = dag.Helm().PackagePush(ctx, directory, "ttl.sh", "helm", "username"+randomString, dag.SetSecret("password", "secret"))
116+
if err != nil {
117+
return err
118+
}
119+
if returnValue {
120+
return fmt.Errorf("should return false because chart already exists")
121+
}
122+
123+
return nil
124+
}
125+
86126
func (m *Go) HelmTest(
87127
// method call context
88128
ctx context.Context,

0 commit comments

Comments
 (0)