-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test generateArgoApplication() all at once * trim space off from doc; add more tests * add simple e2e test
- Loading branch information
Showing
5 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
schema: v2 | ||
namespace: myns | ||
repository: stable | ||
context: mycontext | ||
repositories: | ||
fairwinds-stable: | ||
url: https://charts.fairwinds.com/stable | ||
minimum_versions: | ||
helm: 3.4.1 | ||
reckoner: 4.3.1 | ||
gitops: | ||
argocd: | ||
kind: Application | ||
apiVersion: argoproj.io/v1alpha1 | ||
metadata: | ||
namespace: argocd | ||
annotations: | ||
one_key: one_value | ||
spec: | ||
destination: | ||
namespace: some_value | ||
server: https://kubernetes.default.svc | ||
project: default | ||
source: | ||
# path: manifests | ||
repoURL: https://github.com/someuser/clustername.git | ||
directory: | ||
recurse: true | ||
# plugin: | ||
# name: argocd-vault-plugin | ||
syncPolicy: | ||
automated: | ||
prune: true | ||
syncOptions: | ||
- CreateNamespace=true | ||
- PruneLast=true | ||
namespace_management: | ||
default: | ||
metadata: | ||
annotations: | ||
insights.fairwinds.com/adminOnly: "true" | ||
labels: | ||
ManagedBy: Fairwinds | ||
settings: | ||
overwrite: true | ||
releases: | ||
- name: rbac-manager | ||
namespace: rbac-manager | ||
namespace_management: | ||
settings: | ||
overwrite: true | ||
chart: rbac-manager | ||
version: 1.11.1 | ||
repository: fairwinds-stable | ||
|
||
gitops: | ||
argocd: | ||
metadata: | ||
annotations: | ||
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: some_channel | ||
spec: | ||
project: different_project | ||
source: | ||
path: some_totally_different_path | ||
repoURL: https://github.com/another_user/another_repo.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "2" | ||
name: Shell Executor Secret | ||
vars: | ||
course: ../course_files/27_gitops.yaml | ||
namespace: 27-gitops | ||
release: shell-executor-chart | ||
testcases: | ||
- name: 27 - template course | ||
steps: | ||
- script: | | ||
reckoner template -a {{.course}} --output-dir 27_gitops_output | ||
assertions: | ||
- result.code ShouldEqual 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package reckoner | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/fairwindsops/reckoner/pkg/course" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_generateArgoApplication(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cFile course.FileV2 | ||
want course.ArgoApplication | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "ensure_defaults", | ||
cFile: course.FileV2{ | ||
Releases: []*course.Release{ | ||
{ | ||
Name: "somename", | ||
Namespace: "somens", | ||
Repository: "somerepo", | ||
GitOps: course.GitOps{ // release-specific *addition* | ||
ArgoCD: course.ArgoApplication{ | ||
Metadata: course.ArgoApplicationMetadata{ | ||
Annotations: map[string]string{ | ||
"notifications.argoproj.io/subscribe.on-sync-succeeded.slack": "fairwindsops-infra-argocd", | ||
}, | ||
}, | ||
Spec: course.ArgoApplicationSpec{ | ||
Source: course.ArgoApplicationSpecSource{ | ||
Directory: course.ArgoApplicationSpecSourceDirectory{ | ||
Recurse: true, // release-specific *override* | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
GitOps: course.GitOps{ | ||
ArgoCD: course.ArgoApplication{ | ||
Spec: course.ArgoApplicationSpec{ | ||
Source: course.ArgoApplicationSpecSource{ | ||
Directory: course.ArgoApplicationSpecSourceDirectory{ | ||
Recurse: false, // exists here only to be overridden by the release-specific instance | ||
}, | ||
// Path: "somepath", // omitting this tests more functionality | ||
RepoURL: "https://domain.tld/someorg/somerepo.git", | ||
}, | ||
// Destination: course.ArgoApplicationSpecDestination{}, // omitting this tests defaults | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: course.ArgoApplication{ | ||
Kind: "Application", | ||
APIVersion: "argoproj.io/v1alpha1", | ||
Metadata: course.ArgoApplicationMetadata{ | ||
Name: "somename", | ||
Annotations: map[string]string{ | ||
"notifications.argoproj.io/subscribe.on-sync-succeeded.slack": "fairwindsops-infra-argocd", | ||
}, | ||
}, | ||
Spec: course.ArgoApplicationSpec{ | ||
Source: course.ArgoApplicationSpecSource{ | ||
Directory: course.ArgoApplicationSpecSourceDirectory{ | ||
Recurse: true, | ||
}, | ||
Path: "somename", | ||
RepoURL: "https://domain.tld/someorg/somerepo.git", | ||
}, | ||
Destination: course.ArgoApplicationSpecDestination{ | ||
Server: "https://kubernetes.default.svc", | ||
Namespace: "somens", | ||
}, | ||
Project: "default", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := generateArgoApplication(*tt.cFile.Releases[0], tt.cFile) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("generateArgoApplication() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package reckoner | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_splitYAML(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
yamlFile []byte | ||
want [][]byte | ||
wantNumberOfDocs int | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "one_document", | ||
yamlFile: []byte("---\nfield: \"value\"\n"), | ||
want: [][]byte{ | ||
[]byte("field: value"), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "multi_documents", | ||
yamlFile: []byte("---\nfield:\n nested: value\n---\nanother: second\n"), | ||
want: [][]byte{ | ||
[]byte("field:\n nested: value"), | ||
[]byte("another: second"), | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
docs, err := splitYAML(tt.yamlFile) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("splitYAML() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if len(tt.want) != len(docs) { | ||
t.Errorf("splitYAML() produced different number of YAML documents than expected; wanted = %v, got %v", tt.wantNumberOfDocs, len(docs)) | ||
} | ||
|
||
assert.Equal(t, tt.want, docs) | ||
}) | ||
} | ||
} |