mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-22 15:41:47 +00:00
Add tests for source oci command
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
parent
10a0c9df86
commit
7cfbbf381a
13 changed files with 197 additions and 2 deletions
61
cmd/flux/create_source_oci_test.go
Normal file
61
cmd/flux/create_source_oci_test.go
Normal file
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -388,6 +388,7 @@ func resetCmdArgs() {
|
|||
getArgs = GetFlags{}
|
||||
sourceHelmArgs = sourceHelmFlags{}
|
||||
secretGitArgs = NewSecretGitFlags()
|
||||
*kubeconfigArgs.Namespace = rootArgs.defaults.Namespace
|
||||
}
|
||||
|
||||
func isChangeError(err error) bool {
|
||||
|
|
|
|||
71
cmd/flux/source_oci_test.go
Normal file
71
cmd/flux/source_oci_test.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
5
cmd/flux/testdata/oci/create_source_oci.golden
vendored
Normal file
5
cmd/flux/testdata/oci/create_source_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
► applying OCIRepository
|
||||
✔ OCIRepository created
|
||||
◎ waiting for OCIRepository reconciliation
|
||||
✔ OCIRepository reconciliation completed
|
||||
✔ fetched revision: 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de
|
||||
2
cmd/flux/testdata/oci/delete_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/delete_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
► deleting source oci thrfg in {{ .ns }} namespace
|
||||
✔ source oci deleted
|
||||
12
cmd/flux/testdata/oci/export.golden
vendored
Normal file
12
cmd/flux/testdata/oci/export.golden
vendored
Normal file
|
|
@ -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
|
||||
|
||||
14
cmd/flux/testdata/oci/export_with_secret.golden
vendored
Normal file
14
cmd/flux/testdata/oci/export_with_secret.golden
vendored
Normal file
|
|
@ -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
|
||||
|
||||
2
cmd/flux/testdata/oci/get_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/get_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
NAME REVISION SUSPENDED READY MESSAGE
|
||||
thrfg 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de False True stored artifact for revision '3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de'
|
||||
4
cmd/flux/testdata/oci/reconcile_oci.golden
vendored
Normal file
4
cmd/flux/testdata/oci/reconcile_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
► annotating OCIRepository thrfg in {{ .ns }} namespace
|
||||
✔ OCIRepository annotated
|
||||
◎ waiting for OCIRepository reconciliation
|
||||
✔ fetched revision 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de
|
||||
5
cmd/flux/testdata/oci/resume_oci.golden
vendored
Normal file
5
cmd/flux/testdata/oci/resume_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
► resuming source oci thrfg in {{ .ns }} namespace
|
||||
✔ source oci resumed
|
||||
◎ waiting for OCIRepository reconciliation
|
||||
✔ OCIRepository reconciliation completed
|
||||
✔ fetched revision 3b6cdcc7adcc9a84d3214ee1c029543789d90b5ae69debe9efa3f66e982875de
|
||||
2
cmd/flux/testdata/oci/suspend_oci.golden
vendored
Normal file
2
cmd/flux/testdata/oci/suspend_oci.golden
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
► suspending source oci thrfg in {{ .ns }} namespace
|
||||
✔ source oci suspended
|
||||
4
go.sum
4
go.sum
|
|
@ -264,8 +264,8 @@ github.com/fluxcd/image-automation-controller/api v0.23.4 h1:MR7TKGxTaFBObyul7ww
|
|||
github.com/fluxcd/image-automation-controller/api v0.23.4/go.mod h1:wTxI65xywGEULsKR+eCw0H9uNHqSlISYYeozYIRPPx8=
|
||||
github.com/fluxcd/image-reflector-controller/api v0.19.2 h1:ZWM+v05M/f01Q/MHuasQWYY2EtD9B/q4CsewK01ROrU=
|
||||
github.com/fluxcd/image-reflector-controller/api v0.19.2/go.mod h1:WvPujFOXzWttkETUxkCgP9BesCTAfVYzgCeZXu43nY4=
|
||||
github.com/fluxcd/kustomize-controller/api v0.26.2 h1:ll54Lhc/8mWQmyveLZvlo/aMgBrdctO3dL/EivT5Qik=
|
||||
github.com/fluxcd/kustomize-controller/api v0.26.2/go.mod h1:f16v3IErWGQJ0WXtpOW3ATjFukz/KhbkanqS9ZTM8ks=
|
||||
github.com/fluxcd/kustomize-controller/api v0.26.2-0.20220621190919-7681bda98076 h1:rsvWmqJTWRYb/DJvKA5QH6P8ctNZaH5TCg7rM/8qmec=
|
||||
github.com/fluxcd/kustomize-controller/api v0.26.2-0.20220621190919-7681bda98076/go.mod h1:f16v3IErWGQJ0WXtpOW3ATjFukz/KhbkanqS9ZTM8ks=
|
||||
github.com/fluxcd/notification-controller/api v0.24.0 h1:pvLcCD1HT+x0Hup8VLfDrVGFDK33oJKNC7WX6mtEEh0=
|
||||
github.com/fluxcd/notification-controller/api v0.24.0/go.mod h1:pld1fyodxqdWPBr+Ez+kTixmtmO2o3o0I5Zf5wQDHGM=
|
||||
github.com/fluxcd/pkg/apis/acl v0.0.3 h1:Lw0ZHdpnO4G7Zy9KjrzwwBmDZQuy4qEjaU/RvA6k1lc=
|
||||
|
|
|
|||
Loading…
Reference in a new issue