Merge pull request #2441 from andrewjjenkins/fix-trace-test-tz

Fix failure in TestTrace/* when timezone isn't UTC
pull/2452/head
Stefan Prodan 3 years ago committed by GitHub
commit 1ff8c2806c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@ Status: Managed by Flux
HelmRelease: podinfo HelmRelease: podinfo
Namespace: {{ .ns }} Namespace: {{ .ns }}
Revision: 6.0.0 Revision: 6.0.0
Status: Last reconciled at 2021-07-16 15:42:20 +0000 UTC Status: Last reconciled at {{ .helmReleaseLastReconcile }}
Message: Release reconciliation succeeded Message: Release reconciliation succeeded
--- ---
HelmChart: podinfo-podinfo HelmChart: podinfo-podinfo
@ -14,12 +14,12 @@ Namespace: {{ .fluxns }}
Chart: podinfo Chart: podinfo
Version: 6.0.0 Version: 6.0.0
Revision: 6.0.0 Revision: 6.0.0
Status: Last reconciled at 2021-07-16 15:32:09 +0000 UTC Status: Last reconciled at {{ .helmChartLastReconcile }}
Message: Fetched revision: 6.0.0 Message: Fetched revision: 6.0.0
--- ---
HelmRepository: podinfo HelmRepository: podinfo
Namespace: {{ .fluxns }} Namespace: {{ .fluxns }}
URL: https://stefanprodan.github.io/podinfo URL: https://stefanprodan.github.io/podinfo
Revision: 8411f23d07d3701f0e96e7d9e503b7936d7e1d56 Revision: 8411f23d07d3701f0e96e7d9e503b7936d7e1d56
Status: Last reconciled at 2021-07-11 00:25:46 +0000 UTC Status: Last reconciled at {{ .helmRepositoryLastReconcile }}
Message: Fetched revision: 8411f23d07d3701f0e96e7d9e503b7936d7e1d56 Message: Fetched revision: 8411f23d07d3701f0e96e7d9e503b7936d7e1d56

@ -7,7 +7,7 @@ Kustomization: infrastructure
Namespace: {{ .fluxns }} Namespace: {{ .fluxns }}
Path: ./infrastructure Path: ./infrastructure
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
Status: Last reconciled at 2021-08-01 04:52:56 +0000 UTC Status: Last reconciled at {{ .kustomizationLastReconcile }}
Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f Message: Applied revision: main/696f056df216eea4f9401adbee0ff744d4df390f
--- ---
GitRepository: flux-system GitRepository: flux-system
@ -15,5 +15,5 @@ Namespace: {{ .fluxns }}
URL: ssh://git@github.com/example/repo URL: ssh://git@github.com/example/repo
Branch: main Branch: main
Revision: main/696f056df216eea4f9401adbee0ff744d4df390f Revision: main/696f056df216eea4f9401adbee0ff744d4df390f
Status: Last reconciled at 2021-07-20 00:48:16 +0000 UTC Status: Last reconciled at {{ .gitRepositoryLastReconcile }}
Message: Fetched revision: main/696f056df216eea4f9401adbee0ff744d4df390f Message: Fetched revision: main/696f056df216eea4f9401adbee0ff744d4df390f

@ -5,6 +5,7 @@ package main
import ( import (
"testing" "testing"
"time"
) )
func TestTraceNoArgs(t *testing.T) { func TestTraceNoArgs(t *testing.T) {
@ -15,36 +16,54 @@ func TestTraceNoArgs(t *testing.T) {
cmd.runTestCmd(t) cmd.runTestCmd(t)
} }
func toLocalTime(t *testing.T, in string) string {
ts, err := time.Parse(time.RFC3339, in)
if err != nil {
t.Fatalf("Error converting golden test time '%s': %v", in, err)
}
return ts.Local().String()
}
func TestTrace(t *testing.T) { func TestTrace(t *testing.T) {
cases := []struct { cases := []struct {
name string name string
args string args string
objectFile string objectFile string
goldenFile string goldenFile string
tmpl map[string]string
}{ }{
{ {
"Deployment", "Deployment",
"trace podinfo --kind deployment --api-version=apps/v1", "trace podinfo --kind deployment --api-version=apps/v1",
"testdata/trace/deployment.yaml", "testdata/trace/deployment.yaml",
"testdata/trace/deployment.golden", "testdata/trace/deployment.golden",
map[string]string{
"ns": allocateNamespace("podinfo"),
"fluxns": allocateNamespace("flux-system"),
"helmReleaseLastReconcile": toLocalTime(t, "2021-07-16T15:42:20Z"),
"helmChartLastReconcile": toLocalTime(t, "2021-07-16T15:32:09Z"),
"helmRepositoryLastReconcile": toLocalTime(t, "2021-07-11T00:25:46Z"),
},
}, },
{ {
"HelmRelease", "HelmRelease",
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2beta1", "trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2beta1",
"testdata/trace/helmrelease.yaml", "testdata/trace/helmrelease.yaml",
"testdata/trace/helmrelease.golden", "testdata/trace/helmrelease.golden",
map[string]string{
"ns": allocateNamespace("podinfo"),
"fluxns": allocateNamespace("flux-system"),
"kustomizationLastReconcile": toLocalTime(t, "2021-08-01T04:52:56Z"),
"gitRepositoryLastReconcile": toLocalTime(t, "2021-07-20T00:48:16Z"),
},
}, },
} }
for _, tc := range cases { for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
tmpl := map[string]string{ testEnv.CreateObjectFile(tc.objectFile, tc.tmpl, t)
"ns": allocateNamespace("podinfo"),
"fluxns": allocateNamespace("flux-system"),
}
testEnv.CreateObjectFile(tc.objectFile, tmpl, t)
cmd := cmdTestCase{ cmd := cmdTestCase{
args: tc.args + " -n=" + tmpl["ns"], args: tc.args + " -n=" + tc.tmpl["ns"],
assert: assertGoldenTemplateFile(tc.goldenFile, tmpl), assert: assertGoldenTemplateFile(tc.goldenFile, tc.tmpl),
} }
cmd.runTestCmd(t) cmd.runTestCmd(t)
}) })

Loading…
Cancel
Save