Skip to content

Commit

Permalink
Add test case for Flagger CRDs
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Sep 10, 2024
1 parent 85d0af7 commit 0532660
Show file tree
Hide file tree
Showing 4 changed files with 927 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/timoni/mod_vendor_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path"
"testing"

"github.com/bsm/gomega/types"
"github.com/mattn/go-shellwords"
. "github.com/onsi/gomega"
)
Expand All @@ -32,25 +33,32 @@ func TestVendorCrd(t *testing.T) {
// make install
// cd cmd/timoni/
// timoni mod vendor crd testdata/crd/golden/ -f testdata/crd/source/cert-manager.crds.yaml
// timoni mod vendor crd testdata/crd/golden/ -f testdata/crd/source/flagger.crds.yaml
goldenPath := "testdata/crd/golden/cue.mod/"
crdPath := "testdata/crd/source/cert-manager.crds.yaml"

tmpDir := t.TempDir()
genPath := path.Join(tmpDir, "cue.mod")

g := NewWithT(t)

err := os.MkdirAll(genPath, os.ModePerm)
g.Expect(err).ToNot(HaveOccurred())

output, err := executeCommand(fmt.Sprintf(
"mod vendor crd %s -f %s",
tmpDir,
crdPath,
))
g.Expect(err).ToNot(HaveOccurred())
g.Expect(output).To(ContainSubstring("cert-manager.io/issuer/v1"))
for crdPath, outputMatcher := range map[string]types.GomegaMatcher{
"testdata/crd/source/cert-manager.crds.yaml": ContainSubstring("cert-manager.io/issuer/v1"),
"testdata/crd/source/flagger.crds.yaml": ContainSubstring("flagger.app/canary/v1beta1"),
} {
output, err := executeCommand(fmt.Sprintf(
"mod vendor crd %s -f %s",
tmpDir,
crdPath,
))
g.Expect(err).ToNot(HaveOccurred())
g.Expect(output).To(outputMatcher)
}

diffArgs := fmt.Sprintf("--no-pager diff --no-index %s %s", genPath, goldenPath)

args, err := shellwords.Parse(diffArgs)
g.Expect(err).ToNot(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Code generated by timoni. DO NOT EDIT.

//timoni:generate timoni vendor crd -f testdata/crd/source/flagger.crds.yaml

package v1beta1

import "strings"

// AlertProvider is the Schema for the AlertProvider API.
#AlertProvider: {
// APIVersion defines the versioned schema of this representation
// of an object. Servers should convert recognized schemas to the
// latest internal value, and may reject unrecognized values.
// More info:
// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
apiVersion: "flagger.app/v1beta1"

// Kind is a string value representing the REST resource this
// object represents. Servers may infer this from the endpoint
// the client submits requests to. Cannot be updated. In
// CamelCase. More info:
// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
kind: "AlertProvider"
metadata!: {
name!: strings.MaxRunes(253) & strings.MinRunes(1) & {
string
}
namespace!: strings.MaxRunes(63) & strings.MinRunes(1) & {
string
}
labels?: {
[string]: string
}
annotations?: {
[string]: string
}
}

// AlertProviderSpec defines the desired state of a AlertProvider.
spec!: #AlertProviderSpec
}

// AlertProviderSpec defines the desired state of a AlertProvider.
#AlertProviderSpec: matchN(1, [{
type!: _
address!: _
}, {
type!: _
secretRef!: _
}]) & {
// Hook URL address of this provider
address?: string

// Alert channel for this provider
channel?: string

// Http/s proxy of this provider
proxy?: string
secretRef?: {
// Name of the Kubernetes secret
name!: string
}

// Type of this provider
type?: "slack" | "msteams" | "discord" | "rocket" | "gchat"

// Bot username for this provider
username?: string
}
Loading

0 comments on commit 0532660

Please sign in to comment.