Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 30 additions & 72 deletions apis/dev/v1alpha1/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ func TestValidate(t *testing.T) {
}{
"MinimalValid": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
},
},
},
"MaximalValid": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
ProjectPackageMetadata: ProjectPackageMetadata{
Expand Down Expand Up @@ -93,9 +89,7 @@ func TestValidate(t *testing.T) {
},
"MissingRepository": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{},
},
expectedErrors: []string{
Expand All @@ -104,9 +98,7 @@ func TestValidate(t *testing.T) {
},
"AbsolutePaths": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Paths: &ProjectPaths{
Expand All @@ -128,9 +120,7 @@ func TestValidate(t *testing.T) {
},
"EmptyArchitectures": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Architectures: []string{},
Expand All @@ -142,9 +132,7 @@ func TestValidate(t *testing.T) {
},
"ValidSchemaLanguages": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Schemas: &ProjectSchemas{
Expand All @@ -155,9 +143,7 @@ func TestValidate(t *testing.T) {
},
"EmptySchemaLanguages": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Schemas: &ProjectSchemas{
Expand All @@ -171,9 +157,7 @@ func TestValidate(t *testing.T) {
},
"UnsupportedSchemaLanguage": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Schemas: &ProjectSchemas{
Expand All @@ -187,9 +171,7 @@ func TestValidate(t *testing.T) {
},
"ValidAPIDependency": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -207,9 +189,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyNoType": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -227,9 +207,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyNoSource": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -245,9 +223,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyMultipleSources": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -269,9 +245,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyGitEmptyRepository": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -290,9 +264,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyHTTPEmptyURL": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -311,9 +283,7 @@ func TestValidate(t *testing.T) {
},
"InvalidAPIDependencyK8sEmptyVersion": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Dependencies: []Dependency{
Expand All @@ -332,9 +302,7 @@ func TestValidate(t *testing.T) {
},
"ValidDirectoryFunction": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -346,9 +314,7 @@ func TestValidate(t *testing.T) {
},
"ValidTarballFunction": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -360,7 +326,7 @@ func TestValidate(t *testing.T) {
},
"FunctionMissingSource": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -374,7 +340,7 @@ func TestValidate(t *testing.T) {
},
"FunctionUnknownSource": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -389,7 +355,7 @@ func TestValidate(t *testing.T) {
},
"FunctionDirectorySourceMissingDirectory": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -404,7 +370,7 @@ func TestValidate(t *testing.T) {
},
"FunctionTarballSourceMissingTarball": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -419,7 +385,7 @@ func TestValidate(t *testing.T) {
},
"FunctionMultipleSources": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -435,7 +401,7 @@ func TestValidate(t *testing.T) {
},
"FunctionDirectoryEmptyName": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -450,7 +416,7 @@ func TestValidate(t *testing.T) {
},
"FunctionTarballEmptyPathPrefix": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -465,7 +431,7 @@ func TestValidate(t *testing.T) {
},
"FunctionTarballAbsolutePathPrefix": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{{
Expand All @@ -480,7 +446,7 @@ func TestValidate(t *testing.T) {
},
"FunctionDuplicateName": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{Name: "my-project"},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Functions: []Function{
Expand Down Expand Up @@ -524,9 +490,7 @@ func TestDefault(t *testing.T) {
}{
"FullySpecified": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
ProjectPackageMetadata: ProjectPackageMetadata{
Expand Down Expand Up @@ -559,9 +523,7 @@ func TestDefault(t *testing.T) {
},
},
want: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
ProjectPackageMetadata: ProjectPackageMetadata{
Expand Down Expand Up @@ -597,17 +559,13 @@ func TestDefault(t *testing.T) {
},
"MinimalValid": {
input: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
},
},
want: &Project{
ObjectMeta: metav1.ObjectMeta{
Name: "my-project",
},
Name: "my-project",
Spec: ProjectSpec{
Repository: "xpkg.upbound.io/acmeco/my-project",
Paths: &ProjectPaths{
Expand Down
11 changes: 3 additions & 8 deletions cmd/crossplane/composition/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"

"github.com/spf13/afero"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -183,13 +182,9 @@ func (c *generateCmd) newComposition() (*apiextv1.Composition, string, error) {
}

comp := &apiextv1.Composition{
TypeMeta: metav1.TypeMeta{
APIVersion: apiextv1.CompositionGroupVersionKind.GroupVersion().String(),
Kind: apiextv1.CompositionGroupVersionKind.Kind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
APIVersion: apiextv1.CompositionGroupVersionKind.GroupVersion().String(),
Kind: apiextv1.CompositionGroupVersionKind.Kind,
Name: name,
Spec: apiextv1.CompositionSpec{
CompositeTypeRef: apiextv1.TypeReference{
APIVersion: fmt.Sprintf("%s/%s", group, version),
Expand Down
5 changes: 2 additions & 3 deletions cmd/crossplane/dependency/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ import (

"github.com/crossplane/crossplane-runtime/v2/pkg/logging"

"github.com/crossplane/cli/v2/cmd/crossplane/common"
"github.com/crossplane/cli/v2/internal/config"
"github.com/crossplane/cli/v2/internal/terminal"
)

func TestAddGitAuth(t *testing.T) {
testDependencyGitAuth(t, func(serverURL, projectFile, cacheDir, token string) error {
c := &AddCmd{Package: serverURL + "/repo.git", GitRef: "main", ProjectFile: projectFile, CacheDir: cacheDir, GitFlags: common.GitFlags{GitToken: token, GitUsername: "test-user"}}
c := &AddCmd{Package: serverURL + "/repo.git", GitRef: "main", ProjectFile: projectFile, CacheDir: cacheDir, GitToken: token, GitUsername: "test-user"}
return c.Run(logging.NewNopLogger(), terminal.NewSpinnerPrinter(io.Discard, false), &config.Config{})
})
}

func TestUpdateCacheGitAuth(t *testing.T) {
testDependencyGitAuth(t, func(_, projectFile, cacheDir, token string) error {
c := &UpdateCacheCmd{ProjectFile: projectFile, CacheDir: cacheDir, GitFlags: common.GitFlags{GitToken: token, GitUsername: "test-user"}}
c := &UpdateCacheCmd{ProjectFile: projectFile, CacheDir: cacheDir, GitToken: token, GitUsername: "test-user"}
return c.Run(logging.NewNopLogger(), terminal.NewSpinnerPrinter(io.Discard, false), &config.Config{})
})
}
Expand Down
15 changes: 5 additions & 10 deletions cmd/crossplane/function/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/spf13/afero"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"

apiextv1 "github.com/crossplane/crossplane/apis/v2/apiextensions/v1"
Expand Down Expand Up @@ -618,10 +617,8 @@ func TestAddCompositionStep(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
comp := &apiextv1.Composition{
TypeMeta: metav1.TypeMeta{
APIVersion: "apiextensions.crossplane.io/v1",
Kind: "Composition",
},
APIVersion: "apiextensions.crossplane.io/v1",
Kind: "Composition",
Spec: apiextv1.CompositionSpec{
Pipeline: tc.start,
},
Expand Down Expand Up @@ -652,11 +649,9 @@ func TestAddStepToComposition(t *testing.T) {
}{
"PrependsAndPersists": {
comp: &apiextv1.Composition{
TypeMeta: metav1.TypeMeta{
APIVersion: "apiextensions.crossplane.io/v1",
Kind: "Composition",
},
ObjectMeta: metav1.ObjectMeta{Name: "test-comp"},
APIVersion: "apiextensions.crossplane.io/v1",
Kind: "Composition",
Name: "test-comp",
Spec: apiextv1.CompositionSpec{
CompositeTypeRef: apiextv1.TypeReference{
APIVersion: "example.org/v1",
Expand Down
Loading
Loading