diff --git a/cmd/flux/create_source_oci_test.go b/cmd/flux/create_source_oci_test.go new file mode 100644 index 0000000000000000000000000000000000000000..027c17899f35cc7f7ed16c8fd75026586b71a3b8 --- /dev/null +++ b/cmd/flux/create_source_oci_test.go @@ -0,0 +1,61 @@ +/* +Copyright 2022 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "testing" +) + +func TestCreateSourceOCI(t *testing.T) { + tests := []struct { + name string + args string + assertFunc assertFunc + }{ + { + name: "NoArgs", + args: "create source oci", + assertFunc: assertError("name is required"), + }, + { + name: "NoURL", + args: "create source oci podinfo", + assertFunc: assertError("url is required"), + }, + { + name: "export manifest", + args: "create source oci podinfo --url=ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --export", + assertFunc: assertGoldenFile("./testdata/oci/export.golden"), + }, + { + name: "export manifest with secret", + args: "create source oci podinfo --url=ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m --secret-ref=creds --export", + assertFunc: assertGoldenFile("./testdata/oci/export_with_secret.golden"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cmd := cmdTestCase{ + args: tt.args, + assert: tt.assertFunc, + } + + cmd.runTestCmd(t) + }) + } +} diff --git a/cmd/flux/image_test.go b/cmd/flux/image_test.go index a0e0b2574e89998ac86091e73b4aa7f5273e35e3..155326fadd23ac29bd32ccd148de4f1a646eef0c 100644 --- a/cmd/flux/image_test.go +++ b/cmd/flux/image_test.go @@ -1,6 +1,22 @@ //go:build e2e // +build e2e +/* +Copyright 2022 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package main import "testing" diff --git a/cmd/flux/main_test.go b/cmd/flux/main_test.go index 50127de7d8f5870ca4b4926fa82684e7dcbddf7e..59568dee79fd360e5d4c06c666f244b17c6ec632 100644 --- a/cmd/flux/main_test.go +++ b/cmd/flux/main_test.go @@ -388,6 +388,7 @@ func resetCmdArgs() { getArgs = GetFlags{} sourceHelmArgs = sourceHelmFlags{} secretGitArgs = NewSecretGitFlags() + *kubeconfigArgs.Namespace = rootArgs.defaults.Namespace } func isChangeError(err error) bool { diff --git a/cmd/flux/source_oci_test.go b/cmd/flux/source_oci_test.go new file mode 100644 index 0000000000000000000000000000000000000000..568ac73ee6f9e36717c1b9d47206831e9f516f3c --- /dev/null +++ b/cmd/flux/source_oci_test.go @@ -0,0 +1,71 @@ +//go:build e2e +// +build e2e + +/* +Copyright 2022 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "testing" +) + +func TestSourceOCI(t *testing.T) { + cases := []struct { + args string + goldenFile string + }{ + { + "create source oci thrfg --url=ghcr.io/stefanprodan/manifests/podinfo --tag=6.1.6 --interval 10m", + "testdata/oci/create_source_oci.golden", + }, + { + "get source oci thrfg", + "testdata/oci/get_oci.golden", + }, + { + "reconcile source oci thrfg", + "testdata/oci/reconcile_oci.golden", + }, + { + "suspend source oci thrfg", + "testdata/oci/suspend_oci.golden", + }, + { + "resume source oci thrfg", + "testdata/oci/resume_oci.golden", + }, + { + "delete source oci thrfg --silent", + "testdata/oci/delete_oci.golden", + }, + } + + namespace := allocateNamespace("oci-test") + del, err := setupTestNamespace(namespace) + if err != nil { + t.Fatal(err) + } + defer del() + + for _, tc := range cases { + cmd := cmdTestCase{ + args: tc.args + " -n=" + namespace, + assert: assertGoldenTemplateFile(tc.goldenFile, map[string]string{"ns": namespace}), + } + cmd.runTestCmd(t) + } +} diff --git a/cmd/flux/testdata/oci/create_source_oci.golden b/cmd/flux/testdata/oci/create_source_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..9cca413855edf907c08bbfeadc251a6ca0d8dae1 --- /dev/null +++ b/cmd/flux/testdata/oci/create_source_oci.golden @@ -0,0 +1,5 @@ +► applying OCIRepository +✔ OCIRepository created +◎ waiting for OCIRepository reconciliation +✔ OCIRepository reconciliation completed +✔ fetched revision: 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de diff --git a/cmd/flux/testdata/oci/delete_oci.golden b/cmd/flux/testdata/oci/delete_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..8e8599fa1224483a6291987b8071c1d05573f42a --- /dev/null +++ b/cmd/flux/testdata/oci/delete_oci.golden @@ -0,0 +1,2 @@ +► deleting source oci thrfg in {{ .ns }} namespace +✔ source oci deleted diff --git a/cmd/flux/testdata/oci/export.golden b/cmd/flux/testdata/oci/export.golden new file mode 100644 index 0000000000000000000000000000000000000000..82d5fa19b5536947d9543988f935afd41f4100ca --- /dev/null +++ b/cmd/flux/testdata/oci/export.golden @@ -0,0 +1,12 @@ +--- +apiVersion: source.toolkit.fluxcd.io/v1beta2 +kind: OCIRepository +metadata: + name: podinfo + namespace: flux-system +spec: + interval: 10m0s + ref: + tag: 6.1.6 + url: ghcr.io/stefanprodan/manifests/podinfo + diff --git a/cmd/flux/testdata/oci/export_with_secret.golden b/cmd/flux/testdata/oci/export_with_secret.golden new file mode 100644 index 0000000000000000000000000000000000000000..79fd98a5c92187f6ff79982ea9c57763fa20e04f --- /dev/null +++ b/cmd/flux/testdata/oci/export_with_secret.golden @@ -0,0 +1,14 @@ +--- +apiVersion: source.toolkit.fluxcd.io/v1beta2 +kind: OCIRepository +metadata: + name: podinfo + namespace: flux-system +spec: + interval: 10m0s + ref: + tag: 6.1.6 + secretRef: + name: creds + url: ghcr.io/stefanprodan/manifests/podinfo + diff --git a/cmd/flux/testdata/oci/get_oci.golden b/cmd/flux/testdata/oci/get_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..f4fa8333baf82736269f8836a918f8637f212077 --- /dev/null +++ b/cmd/flux/testdata/oci/get_oci.golden @@ -0,0 +1,2 @@ +NAME REVISION SUSPENDED READY MESSAGE +thrfg 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de False True stored artifact for revision '3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de' diff --git a/cmd/flux/testdata/oci/reconcile_oci.golden b/cmd/flux/testdata/oci/reconcile_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..0c258819463f7bf167aca5f38316ceaed3088005 --- /dev/null +++ b/cmd/flux/testdata/oci/reconcile_oci.golden @@ -0,0 +1,4 @@ +► annotating OCIRepository thrfg in {{ .ns }} namespace +✔ OCIRepository annotated +◎ waiting for OCIRepository reconciliation +✔ fetched revision 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de diff --git a/cmd/flux/testdata/oci/resume_oci.golden b/cmd/flux/testdata/oci/resume_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..467514e7d86b04a9e0858b467b814f14d485ff10 --- /dev/null +++ b/cmd/flux/testdata/oci/resume_oci.golden @@ -0,0 +1,5 @@ +► resuming source oci thrfg in {{ .ns }} namespace +✔ source oci resumed +◎ waiting for OCIRepository reconciliation +✔ OCIRepository reconciliation completed +✔ fetched revision 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de diff --git a/cmd/flux/testdata/oci/suspend_oci.golden b/cmd/flux/testdata/oci/suspend_oci.golden new file mode 100644 index 0000000000000000000000000000000000000000..40a0420e3765c36d6d72cd8798bd7fd9e7bc1077 --- /dev/null +++ b/cmd/flux/testdata/oci/suspend_oci.golden @@ -0,0 +1,2 @@ +► suspending source oci thrfg in {{ .ns }} namespace +✔ source oci suspended