mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-23 11:58:51 +00:00
Use shared envTest for unit tests
Speed up unit tests by using a shared envTest. This requires each test to use its own namespace to avoid clobbering objects for other tests. Tests previously took around 8 seconds each, and now the initial test takes 2 seconds with follow up tests taking less than a second each. Also update existing tests that use a fixed namespace to use a generated namespace. Share gold file template function with yaml files. Remove the testClusterMode, and instead rely on MainTest to do the appropriate test setup and rootArgs flag setup. Move the rootArg flag setup out of NewTestEnvKubeManager to avoid side effects. A follow up change can be to push the individual setups from NewTestEnvKubeManager() into their respective TestMain since the harness share little code. Signed-off-by: Allen Porter <allen@thebends.org>
This commit is contained in:
parent
def92e14ee
commit
d45501a129
22 changed files with 165 additions and 122 deletions
8
cmd/flux/testdata/trace/deployment.golden
vendored
8
cmd/flux/testdata/trace/deployment.golden
vendored
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
Object: deployment/podinfo
|
||||
Namespace: podinfo
|
||||
Namespace: {{ .ns }}
|
||||
Status: Managed by Flux
|
||||
---
|
||||
HelmRelease: podinfo
|
||||
Namespace: podinfo
|
||||
Namespace: {{ .ns }}
|
||||
Revision: 6.0.0
|
||||
Status: Last reconciled at 2021-07-16 15:42:20 +0000 UTC
|
||||
Message: Release reconciliation succeeded
|
||||
---
|
||||
HelmChart: podinfo-podinfo
|
||||
Namespace: flux-system
|
||||
Namespace: {{ .fluxns }}
|
||||
Chart: podinfo
|
||||
Version: 6.0.0
|
||||
Revision: 6.0.0
|
||||
|
|
@ -18,7 +18,7 @@ Status: Last reconciled at 2021-07-16 15:32:09 +0000 UTC
|
|||
Message: Fetched revision: 6.0.0
|
||||
---
|
||||
HelmRepository: podinfo
|
||||
Namespace: flux-system
|
||||
Namespace: {{ .fluxns }}
|
||||
URL: https://stefanprodan.github.io/podinfo
|
||||
Revision: 8411f23d07d3701f0e96e7d9e503b7936d7e1d56
|
||||
Status: Last reconciled at 2021-07-11 00:25:46 +0000 UTC
|
||||
|
|
|
|||
27
cmd/flux/testdata/trace/deployment.yaml
vendored
27
cmd/flux/testdata/trace/deployment.yaml
vendored
|
|
@ -2,12 +2,12 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
name: {{ .fluxns }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: podinfo
|
||||
name: {{ .ns }}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
|
|
@ -15,11 +15,10 @@ metadata:
|
|||
labels:
|
||||
app.kubernetes.io/name: podinfo
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: podinfo
|
||||
helm.toolkit.fluxcd.io/name: podinfo
|
||||
helm.toolkit.fluxcd.io/namespace: podinfo
|
||||
helm.toolkit.fluxcd.io/namespace: {{ .ns }}
|
||||
name: podinfo
|
||||
namespace: podinfo
|
||||
namespace: {{ .ns }}
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
|
|
@ -40,9 +39,9 @@ kind: HelmRelease
|
|||
metadata:
|
||||
labels:
|
||||
kustomize.toolkit.fluxcd.io/name: infrastructure
|
||||
kustomize.toolkit.fluxcd.io/namespace: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||
name: podinfo
|
||||
namespace: podinfo
|
||||
namespace: {{ .ns }}
|
||||
spec:
|
||||
chart:
|
||||
spec:
|
||||
|
|
@ -50,7 +49,7 @@ spec:
|
|||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: podinfo
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
interval: 5m
|
||||
status:
|
||||
conditions:
|
||||
|
|
@ -59,7 +58,7 @@ status:
|
|||
reason: ReconciliationSucceeded
|
||||
status: "True"
|
||||
type: Ready
|
||||
helmChart: flux-system/podinfo-podinfo
|
||||
helmChart: {{ .fluxns }}/podinfo-podinfo
|
||||
lastAppliedRevision: 6.0.0
|
||||
lastAttemptedRevision: 6.0.0
|
||||
lastAttemptedValuesChecksum: c31db75d05b7515eba2eef47bd71038c74b2e531
|
||||
|
|
@ -68,7 +67,7 @@ apiVersion: source.toolkit.fluxcd.io/v1beta1
|
|||
kind: HelmChart
|
||||
metadata:
|
||||
name: podinfo-podinfo
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
chart: podinfo
|
||||
sourceRef:
|
||||
|
|
@ -98,7 +97,7 @@ metadata:
|
|||
kustomize.toolkit.fluxcd.io/name: infrastructure
|
||||
kustomize.toolkit.fluxcd.io/namespace: flux-system
|
||||
name: podinfo
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
interval: 5m
|
||||
timeout: 1m0s
|
||||
|
|
@ -121,7 +120,7 @@ apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
|
|||
kind: Kustomization
|
||||
metadata:
|
||||
name: infrastructure
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
path: ./infrastructure/
|
||||
sourceRef:
|
||||
|
|
@ -143,9 +142,9 @@ kind: GitRepository
|
|||
metadata:
|
||||
labels:
|
||||
kustomize.toolkit.fluxcd.io/name: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||
name: flux-system
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
gitImplementation: go-git
|
||||
ref:
|
||||
|
|
|
|||
6
cmd/flux/testdata/trace/helmrelease.golden
vendored
6
cmd/flux/testdata/trace/helmrelease.golden
vendored
|
|
@ -1,17 +1,17 @@
|
|||
|
||||
Object: HelmRelease/podinfo
|
||||
Namespace: podinfo
|
||||
Namespace: {{ .ns }}
|
||||
Status: Managed by Flux
|
||||
---
|
||||
Kustomization: infrastructure
|
||||
Namespace: flux-system
|
||||
Namespace: {{ .fluxns }}
|
||||
Path: ./infrastructure
|
||||
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||
Status: Last reconciled at 2021-08-01 04:52:56 +0000 UTC
|
||||
Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||
---
|
||||
GitRepository: flux-system
|
||||
Namespace: flux-system
|
||||
Namespace: {{ .fluxns }}
|
||||
URL: ssh://git@github.com/example/repo
|
||||
Branch: main
|
||||
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
|
||||
|
|
|
|||
18
cmd/flux/testdata/trace/helmrelease.yaml
vendored
18
cmd/flux/testdata/trace/helmrelease.yaml
vendored
|
|
@ -2,21 +2,21 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
name: {{ .fluxns }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: podinfo
|
||||
name: {{ .ns }}
|
||||
---
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
labels:
|
||||
kustomize.toolkit.fluxcd.io/name: infrastructure
|
||||
kustomize.toolkit.fluxcd.io/namespace: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||
name: podinfo
|
||||
namespace: podinfo
|
||||
namespace: {{ .ns }}
|
||||
spec:
|
||||
chart:
|
||||
spec:
|
||||
|
|
@ -24,7 +24,7 @@ spec:
|
|||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: podinfo
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
interval: 5m
|
||||
status:
|
||||
conditions:
|
||||
|
|
@ -33,7 +33,7 @@ status:
|
|||
reason: ReconciliationSucceeded
|
||||
status: "True"
|
||||
type: Ready
|
||||
helmChart: flux-system/podinfo-podinfo
|
||||
helmChart: {{ .fluxns }}/podinfo-podinfo
|
||||
lastAppliedRevision: 6.0.0
|
||||
lastAttemptedRevision: 6.0.0
|
||||
lastAttemptedValuesChecksum: c31db75d05b7515eba2eef47bd71038c74b2e531
|
||||
|
|
@ -42,7 +42,7 @@ apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
|
|||
kind: Kustomization
|
||||
metadata:
|
||||
name: infrastructure
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
path: ./infrastructure
|
||||
sourceRef:
|
||||
|
|
@ -65,9 +65,9 @@ kind: GitRepository
|
|||
metadata:
|
||||
labels:
|
||||
kustomize.toolkit.fluxcd.io/name: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: flux-system
|
||||
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||
name: flux-system
|
||||
namespace: flux-system
|
||||
namespace: {{ .fluxns }}
|
||||
spec:
|
||||
gitImplementation: go-git
|
||||
ref:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue