test(cmd): refactor release_testing_test.go

Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>
pull/5365/head
Matthew Fisher 5 years ago
parent f185103b60
commit f8ed917830
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -0,0 +1,103 @@
/*
Copyright The Helm 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"
"time"
"k8s.io/helm/pkg/release"
)
const mockTestSuccessTemplate = `apiVersion: v1
kind: Pod
metadata:
annotations:
"helm.sh/hook": test-success
`
func TestReleaseTesting(t *testing.T) {
timestamp := time.Unix(1452902400, 0).UTC()
tests := []cmdTestCase{{
name: "successful test",
cmd: "status test-success",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{
Name: "test-success",
TestSuiteResults: []*release.TestRun{
{
Name: "test-success",
Status: release.TestRunSuccess,
StartedAt: timestamp,
CompletedAt: timestamp,
},
},
})},
golden: "output/test-success.txt",
}, {
name: "test failure",
cmd: "status test-failure",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{
Name: "test-failure",
TestSuiteResults: []*release.TestRun{
{
Name: "test-failure",
Status: release.TestRunFailure,
StartedAt: timestamp,
CompletedAt: timestamp,
},
},
})},
golden: "output/test-failure.txt",
}, {
name: "test unknown",
cmd: "status test-unknown",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{
Name: "test-unknown",
TestSuiteResults: []*release.TestRun{
{
Name: "test-unknown",
Status: release.TestRunUnknown,
StartedAt: timestamp,
CompletedAt: timestamp,
},
},
})},
golden: "output/test-unknown.txt",
}, {
name: "test running",
cmd: "status test-running",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{
Name: "test-running",
TestSuiteResults: []*release.TestRun{
{
Name: "test-running",
Status: release.TestRunRunning,
StartedAt: timestamp,
CompletedAt: timestamp,
},
},
})},
golden: "output/test-running.txt",
}, {
name: "test with no tests",
cmd: "test no-tests",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "no-tests"})},
golden: "output/test-no-tests.txt",
}}
runTestCmd(t, tests)
}

@ -0,0 +1,11 @@
NAME: test-failure
LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default
STATUS: deployed
TEST SUITE:
Last Started: 1977-09-02 22:04:05 +0000 UTC
Last Completed: 1977-09-02 22:04:05 +0000 UTC
TEST STATUS INFO STARTED COMPLETED
test-failure failure 2016-01-16 00:00:00 +0000 UTC 2016-01-16 00:00:00 +0000 UTC

@ -0,0 +1,11 @@
NAME: test-running
LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default
STATUS: deployed
TEST SUITE:
Last Started: 1977-09-02 22:04:05 +0000 UTC
Last Completed: 1977-09-02 22:04:05 +0000 UTC
TEST STATUS INFO STARTED COMPLETED
test-running running 2016-01-16 00:00:00 +0000 UTC 2016-01-16 00:00:00 +0000 UTC

@ -0,0 +1,11 @@
NAME: test-success
LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default
STATUS: deployed
TEST SUITE:
Last Started: 1977-09-02 22:04:05 +0000 UTC
Last Completed: 1977-09-02 22:04:05 +0000 UTC
TEST STATUS INFO STARTED COMPLETED
test-success success 2016-01-16 00:00:00 +0000 UTC 2016-01-16 00:00:00 +0000 UTC

@ -0,0 +1,11 @@
NAME: test-unknown
LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC
NAMESPACE: default
STATUS: deployed
TEST SUITE:
Last Started: 1977-09-02 22:04:05 +0000 UTC
Last Completed: 1977-09-02 22:04:05 +0000 UTC
TEST STATUS INFO STARTED COMPLETED
test-unknown unknown 2016-01-16 00:00:00 +0000 UTC 2016-01-16 00:00:00 +0000 UTC

@ -40,11 +40,12 @@ metadata:
// MockReleaseOptions allows for user-configurable options on mock release objects.
type MockReleaseOptions struct {
Name string
Version int
Chart *chart.Chart
Status Status
Namespace string
Name string
Version int
Chart *chart.Chart
Status Status
Namespace string
TestSuiteResults []*TestRun
}
// Mock creates a mock release object based on options set by MockReleaseOptions. This function should typically not be used outside of testing.
@ -84,14 +85,24 @@ func Mock(opts *MockReleaseOptions) *Release {
scode = opts.Status
}
info := &Info{
FirstDeployed: date,
LastDeployed: date,
Status: scode,
Description: "Release mock",
}
if len(opts.TestSuiteResults) > 0 {
info.LastTestSuiteRun = &TestSuite{
StartedAt: date,
CompletedAt: date,
Results: opts.TestSuiteResults,
}
}
return &Release{
Name: name,
Info: &Info{
FirstDeployed: date,
LastDeployed: date,
Status: scode,
Description: "Release mock",
},
Name: name,
Info: info,
Chart: ch,
Config: map[string]interface{}{"name": "value"},
Version: version,

Loading…
Cancel
Save