|
| 1 | +package reckoner |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/fairwindsops/reckoner/pkg/course" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_generateArgoApplication(t *testing.T) { |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + cFile course.FileV2 |
| 14 | + want course.ArgoApplication |
| 15 | + wantErr bool |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "ensure_defaults", |
| 19 | + cFile: course.FileV2{ |
| 20 | + Releases: []*course.Release{ |
| 21 | + { |
| 22 | + Name: "somename", |
| 23 | + Namespace: "somens", |
| 24 | + Repository: "somerepo", |
| 25 | + GitOps: course.GitOps{ // release-specific *addition* |
| 26 | + ArgoCD: course.ArgoApplication{ |
| 27 | + Metadata: course.ArgoApplicationMetadata{ |
| 28 | + Annotations: map[string]string{ |
| 29 | + "notifications.argoproj.io/subscribe.on-sync-succeeded.slack": "fairwindsops-infra-argocd", |
| 30 | + }, |
| 31 | + }, |
| 32 | + Spec: course.ArgoApplicationSpec{ |
| 33 | + Source: course.ArgoApplicationSpecSource{ |
| 34 | + Directory: course.ArgoApplicationSpecSourceDirectory{ |
| 35 | + Recurse: true, // release-specific *override* |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + GitOps: course.GitOps{ |
| 44 | + ArgoCD: course.ArgoApplication{ |
| 45 | + Spec: course.ArgoApplicationSpec{ |
| 46 | + Source: course.ArgoApplicationSpecSource{ |
| 47 | + Directory: course.ArgoApplicationSpecSourceDirectory{ |
| 48 | + Recurse: false, // exists here only to be overridden by the release-specific instance |
| 49 | + }, |
| 50 | + // Path: "somepath", // omitting this tests more functionality |
| 51 | + RepoURL: "https://domain.tld/someorg/somerepo.git", |
| 52 | + }, |
| 53 | + // Destination: course.ArgoApplicationSpecDestination{}, // omitting this tests defaults |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + want: course.ArgoApplication{ |
| 59 | + Kind: "Application", |
| 60 | + APIVersion: "argoproj.io/v1alpha1", |
| 61 | + Metadata: course.ArgoApplicationMetadata{ |
| 62 | + Name: "somename", |
| 63 | + Annotations: map[string]string{ |
| 64 | + "notifications.argoproj.io/subscribe.on-sync-succeeded.slack": "fairwindsops-infra-argocd", |
| 65 | + }, |
| 66 | + }, |
| 67 | + Spec: course.ArgoApplicationSpec{ |
| 68 | + Source: course.ArgoApplicationSpecSource{ |
| 69 | + Directory: course.ArgoApplicationSpecSourceDirectory{ |
| 70 | + Recurse: true, |
| 71 | + }, |
| 72 | + Path: "somename", |
| 73 | + RepoURL: "https://domain.tld/someorg/somerepo.git", |
| 74 | + }, |
| 75 | + Destination: course.ArgoApplicationSpecDestination{ |
| 76 | + Server: "https://kubernetes.default.svc", |
| 77 | + Namespace: "somens", |
| 78 | + }, |
| 79 | + Project: "default", |
| 80 | + }, |
| 81 | + }, |
| 82 | + wantErr: false, |
| 83 | + }, |
| 84 | + } |
| 85 | + for _, tt := range tests { |
| 86 | + t.Run(tt.name, func(t *testing.T) { |
| 87 | + got, err := generateArgoApplication(*tt.cFile.Releases[0], tt.cFile) |
| 88 | + if (err != nil) != tt.wantErr { |
| 89 | + t.Errorf("generateArgoApplication() error = %v, wantErr %v", err, tt.wantErr) |
| 90 | + return |
| 91 | + } |
| 92 | + assert.Equal(t, tt.want, got) |
| 93 | + }) |
| 94 | + } |
| 95 | +} |
0 commit comments