Skip to content

Commit

Permalink
Merge pull request #37 from puzzle/examples
Browse files Browse the repository at this point in the history
move tests
  • Loading branch information
chrira authored Nov 14, 2024
2 parents a6391ec + 2ac39b6 commit faa6e52
Show file tree
Hide file tree
Showing 25 changed files with 373 additions and 99 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ jobs:
- uses: actions/checkout@v4
- name: Install Dagger CLI
run: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; }
- name: Display module functions
- name: Display Helm module functions
run: dagger functions -m helm/
- name: Run module tests
run: dagger -m helm/examples/go call all
run: dagger -m tests/ call all
- name: Run module integration tests
env:
TEST_HELM_REGISTRY_URL: ${{ secrets.TEST_HELM_REGISTRY_URL }}
TEST_HELM_REGISTRY_REPOSITORY: ${{ secrets.TEST_HELM_REGISTRY_REPOSITORY }}
TEST_HELM_REGISTRY_HELM_USER: ${{ secrets.TEST_HELM_REGISTRY_HELM_USER }}
TEST_HELM_REGISTRY_HELM_PASSWORD: ${{ secrets.TEST_HELM_REGISTRY_HELM_PASSWORD }}
run: |
dagger -m helm/examples/go \
dagger -m tests/ \
call helm-packagepush \
--registry ${TEST_HELM_REGISTRY_URL} \
--repository ${TEST_HELM_REGISTRY_REPOSITORY} \
--username ${TEST_HELM_REGISTRY_HELM_USER} \
--password env:TEST_HELM_REGISTRY_HELM_PASSWORD
- name: Display go examples module functions
run: dagger -m helm/examples/go/ functions
- name: Test shell examples
run: |
source helm/examples/shell/examples.sh
helm_test
helm_version
4 changes: 2 additions & 2 deletions helm/examples/go/dagger.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "go",
"name": "Examples",
"sdk": "go",
"dependencies": [
{
Expand All @@ -8,5 +8,5 @@
}
],
"source": ".",
"engineVersion": "v0.13.5"
"engineVersion": "v0.13.6"
}
14 changes: 6 additions & 8 deletions helm/examples/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module dagger/go
module dagger/examples

go 1.22.5
go 1.23.2

require (
github.com/99designs/gqlgen v0.17.55
Expand All @@ -9,11 +9,15 @@ require (
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0
go.opentelemetry.io/otel/log v0.3.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/sdk/log v0.3.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
go.opentelemetry.io/proto/otlp v1.3.1
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
Expand All @@ -27,14 +31,8 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/sourcegraph/conc v0.3.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.18.0 // indirect
Expand Down
25 changes: 6 additions & 19 deletions helm/examples/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand All @@ -20,20 +19,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vektah/gqlparser/v2 v2.5.17 h1:9At7WblLV7/36nulgekUgIaqHZWn5hxqluxrxGUhOmI=
Expand All @@ -44,6 +35,10 @@ go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-2024051809000
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240518090000-14441aefdf88/go.mod h1:JGG8ebaMO5nXOPnvKEl+DiA4MGwFjCbjsxT1WHIEBPY=
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0 h1:ccBrA8nCY5mM0y5uO7FT0ze4S0TuFcWdDB2FxGMTjkI=
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0/go.mod h1:/9pb6634zi2Lk8LYg9Q0X8Ar6jka4dkFOylBLbVQPCE=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0 h1:bFgvUr3/O4PHj3VQcFEuYKvRZJX1SJDQ+11JXuSB3/w=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0/go.mod h1:xJntEd2KL6Qdg5lwp97HMLQDVeAhrYxmzFseAMDPQ8I=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 h1:CIHWikMsN3wO+wq1Tp5VGdVRTcON+DmOJSfDjXypKOc=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0/go.mod h1:TNupZ6cxqyFEpLXAZW7On+mLFL0/g0TE3unIYL91xWc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA=
Expand All @@ -64,12 +59,8 @@ go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
Expand All @@ -88,9 +79,5 @@ google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
111 changes: 46 additions & 65 deletions helm/examples/go/main.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
// Go examples for the Helm module.
//
// This module defines the examples for the Daggerverse.

package main

import (
"context"
"dagger/go/internal/dagger"
"fmt"

"github.com/sourcegraph/conc/pool"
"dagger/examples/internal/dagger"
)

type Go struct{}

// All executes all tests.
func (m *Go) All(ctx context.Context) error {
p := pool.New().WithErrors().WithContext(ctx)

p.Go(m.HelmVersion)
p.Go(m.HelmTest)

return p.Wait()
}

func (m *Go) HelmVersion(
// method call context
ctx context.Context,
) error {
const expected = "0.1.1"

// dagger call version --directory ./examples/testdata/mychart/
directory := dag.CurrentModule().Source().Directory("./testdata/mychart/")
version, err := dag.Helm().Version(ctx, directory)

if err != nil {
return err
}

if version != expected {
return fmt.Errorf("expected %q, got %q", expected, version)
}
type Examples struct{}

return nil
}

func (h *Go) HelmPackagepush(
// Example on how to call the PackagePush method.
// Packages and pushes a Helm chart to a specified OCI-compatible registry with authentication.
//
// Return: true if the chart was successfully pushed, or false if the chart already exists, with error handling for push failures.
func (h *Examples) HelmPackagepush(
// method call context
ctx context.Context,
// directory that contains the Helm Chart
directory *dagger.Directory,
// URL of the registry
registry string,
// name of the repository
Expand All @@ -53,38 +29,43 @@ func (h *Go) HelmPackagepush(
username string,
// registry login password
password *dagger.Secret,
) error {
// dagger call package-push \
// --registry registry.puzzle.ch \
// --repository helm \
// --username $REGISTRY_HELM_USER \
// --password env:REGISTRY_HELM_PASSWORD \
// --directory ./examples/testdata/mychart/

// directory that contains the Helm Chart
directory := dag.CurrentModule().Source().Directory("./testdata/mychart/")
_, err := dag.Helm().PackagePush(ctx, directory, registry, repository, username, password)

if err != nil {
return err
}

return nil
) (bool, error) {
return dag.
Helm().
PackagePush(ctx, directory, registry, repository, username, password)
}

func (m *Go) HelmTest(
// Example on how to call the Test method.
//
// Run the unit tests for the Helm Chart located inside the directory referenced by the directory parameter.
// Add the directory location with `"."` as `--args` parameter to tell helm unittest where to find the tests inside the passed directory.
//
// Return: The Helm unit test output as string.
func (h *Examples) HelmTest(
// method call context
ctx context.Context,
) error {
args := []string{"."}

// dagger call test --directory ./examples/testdata/mychart/ --args "."
directory := dag.CurrentModule().Source().Directory("./testdata/mychart/")
_, err := dag.Helm().Test(ctx, directory, args)

if err != nil {
return err
}
// directory that contains the Helm Chart, e.g. "./helm/examples/testdata/mychart/"
directory *dagger.Directory,
// Helm Unittest arguments, e.g. "." to reference the Helm Chart root directory inside the passed directory.
args []string,
) (string, error) {
return dag.
Helm().
Test(ctx, directory, args)
}

return nil
// Example on how to call the Version method.
//
// Get and display the version of the Helm Chart located inside the directory referenced by the directory parameter.
//
// Return: The Helm Chart version as string.
func (m *Examples) HelmVersion(
// method call context
ctx context.Context,
// directory that contains the Helm Chart, e.g. "./helm/examples/testdata/mychart/"
chart *dagger.Directory,
) (string, error) {
return dag.
Helm().
Version(ctx, chart)
}
55 changes: 55 additions & 0 deletions helm/examples/shell/examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

#################################################
# Example on how to call the PackagePush method.
# Packages and pushes a Helm chart to a specified OCI-compatible registry with authentication.
# ARGUMENTS:
# directory: directory that contains the Helm Chart
# registry: URL of the registry
# repository: name of the repository
# username: registry login username
# password: registry login password as a Dagger Secret
# RETURN:
# true if the chart was successfully pushed, or false if the chart already exists, with error handling for push failures.
#################################################
function helm_packagepush() {
dagger -m helm/ \
call package-push \
--directory ./helm/examples/testdata/mychart/ \
--registry registry.puzzle.ch \
--repository helm \
--username registry-helm-user \
--password env:REGISTRY_HELM_PASSWORD \
--directory ./examples/testdata/mychart/
}

#################################################
# Example on how to call the Test method.
# Run the unit tests for the Helm Chart located inside the directory referenced by the directory parameter.
# Add the directory location with `"."` as `--args` parameter to tell helm unittest where to find the tests inside the passed directory.
# ARGUMENTS:
# directory: directory that contains the Helm Chart
# args: arguments for the helm test command
# RETURN:
# The Helm unit test output as string.
#################################################
function helm_test() {
dagger -m helm/ \
call test \
--directory ./helm/examples/testdata/mychart/ \
--args "."
}

#################################################
# Example on how to call the Version method.
# Get and display the version of the Helm Chart located inside the directory referenced by the directory parameter.
# ARGUMENTS:
# directory: directory that contains the Helm Chart
# RETURN:
# The Helm Chart version as string.
#################################################
function helm_version() {
dagger -m helm/ \
call version \
--directory ./helm/examples/testdata/mychart/
}
4 changes: 2 additions & 2 deletions helm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p PushOpts) getRepoFqdn() string {

// Get and display the version of the Helm Chart located inside the given directory.
//
// Example usage: dagger call version --directory ./examples/testdata/mychart/
// Example usage: dagger call version --directory ./helm/examples/testdata/mychart/
func (h *Helm) Version(
// method call context
ctx context.Context,
Expand Down Expand Up @@ -158,7 +158,7 @@ func (h *Helm) PackagePush(
// Provide the helm chart directory with pointing to it with the `--directory` flag.
// Add the directory location with `"."` as `--args` parameter to tell helm unittest where to find the helm chart with the tests.
//
// Example usage: dagger call test --directory ./examples/testdata/mychart/ --args "."
// Example usage: dagger call test --directory ./helm/examples/testdata/mychart/ --args "."
func (h *Helm) Test(
// method call context
ctx context.Context,
Expand Down
4 changes: 4 additions & 0 deletions tests/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dagger.gen.go linguist-generated
/internal/dagger/** linguist-generated
/internal/querybuilder/** linguist-generated
/internal/telemetry/** linguist-generated
4 changes: 4 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dagger.gen.go
/internal/dagger
/internal/querybuilder
/internal/telemetry
12 changes: 12 additions & 0 deletions tests/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "go",
"sdk": "go",
"dependencies": [
{
"name": "helm",
"source": "../helm/"
}
],
"source": ".",
"engineVersion": "v0.13.5"
}
Loading

0 comments on commit faa6e52

Please sign in to comment.