mirror of
https://github.com/helm/helm.git
synced 2026-03-14 22:53:51 -04:00
ref(*): remove protobuf timestamps
This commit is contained in:
parent
6345f04190
commit
91a6ebfed5
33 changed files with 121 additions and 278 deletions
|
|
@ -28,7 +28,6 @@ import (
|
|||
"k8s.io/helm/pkg/hapi/chart"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
type releaseInfo struct {
|
||||
|
|
@ -131,18 +130,20 @@ func getReleaseHistory(rls []*release.Release) (history releaseHistory) {
|
|||
for i := len(rls) - 1; i >= 0; i-- {
|
||||
r := rls[i]
|
||||
c := formatChartname(r.Chart)
|
||||
t := timeconv.String(r.Info.LastDeployed)
|
||||
s := r.Info.Status.Code.String()
|
||||
v := r.Version
|
||||
d := r.Info.Description
|
||||
|
||||
rInfo := releaseInfo{
|
||||
Revision: v,
|
||||
Updated: t,
|
||||
Status: s,
|
||||
Chart: c,
|
||||
Description: d,
|
||||
}
|
||||
if !r.Info.LastDeployed.IsZero() {
|
||||
rInfo.Updated = r.Info.LastDeployed.String()
|
||||
|
||||
}
|
||||
history = append(history, rInfo)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func TestHistoryCmd(t *testing.T) {
|
|||
mk("angry-bird", 2, rpb.Status_SUPERSEDED),
|
||||
mk("angry-bird", 1, rpb.Status_SUPERSEDED),
|
||||
},
|
||||
expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n1 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n2 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n",
|
||||
expected: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n1\s+(.*)\s+SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n2(.*)SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n3(.*)SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n4(.*)DEPLOYED\s+foo-0.1.0-beta.1\s+Release mock\n`,
|
||||
},
|
||||
{
|
||||
name: "get history with max limit set",
|
||||
|
|
@ -55,7 +55,7 @@ func TestHistoryCmd(t *testing.T) {
|
|||
mk("angry-bird", 4, rpb.Status_DEPLOYED),
|
||||
mk("angry-bird", 3, rpb.Status_SUPERSEDED),
|
||||
},
|
||||
expected: "REVISION\tUPDATED \tSTATUS \tCHART \tDESCRIPTION \n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\tRelease mock\n",
|
||||
expected: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n3\s+(.*)\s+SUPERSEDED\s+foo-0.1.0-beta.1\s+Release mock\n4\s+(.*)\s+DEPLOYED\s+foo-0.1.0-beta.1\s+Release mock\n`,
|
||||
},
|
||||
{
|
||||
name: "get history with yaml output format",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import (
|
|||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
var listHelp = `
|
||||
|
|
@ -237,8 +236,8 @@ func formatList(rels []*release.Release, colWidth uint) string {
|
|||
md := r.Chart.Metadata
|
||||
c := fmt.Sprintf("%s-%s", md.Name, md.Version)
|
||||
t := "-"
|
||||
if tspb := r.Info.LastDeployed; tspb != nil {
|
||||
t = timeconv.String(tspb)
|
||||
if tspb := r.Info.LastDeployed; !tspb.IsZero() {
|
||||
t = tspb.String()
|
||||
}
|
||||
s := r.Info.Status.Code.String()
|
||||
v := r.Version
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func TestListCmd(t *testing.T) {
|
|||
rels: []*release.Release{
|
||||
helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}),
|
||||
},
|
||||
expected: "NAME \tREVISION\tUPDATED \tSTATUS \tCHART \tNAMESPACE\natlas\t1 \t(.*)\tDEPLOYED\tfoo-0.1.0-beta.1\tdefault \n",
|
||||
expected: `NAME\s+REVISION\s+UPDATED\s+STATUS\s+CHART\s+NAMESPACE\natlas\s+1\s+(.*)\s+DEPLOYED\s+foo-0.1.0-beta.1\s+default`,
|
||||
},
|
||||
{
|
||||
name: "list, one deployed, one failed",
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
var printReleaseTemplate = `REVISION: {{.Release.Version}}
|
||||
|
|
@ -61,7 +60,7 @@ func printRelease(out io.Writer, rel *release.Release) error {
|
|||
data := map[string]interface{}{
|
||||
"Release": rel,
|
||||
"ComputedValues": cfgStr,
|
||||
"ReleaseDate": timeconv.Format(rel.Info.LastDeployed, time.ANSIC),
|
||||
"ReleaseDate": rel.Info.LastDeployed.Format(time.ANSIC),
|
||||
}
|
||||
return tpl(printReleaseTemplate, data, out)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import (
|
|||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
var statusHelp = `
|
||||
|
|
@ -113,8 +112,8 @@ func (s *statusCmd) run() error {
|
|||
// PrintStatus prints out the status of a release. Shared because also used by
|
||||
// install / upgrade
|
||||
func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) {
|
||||
if res.Info.LastDeployed != nil {
|
||||
fmt.Fprintf(out, "LAST DEPLOYED: %s\n", timeconv.String(res.Info.LastDeployed))
|
||||
if !res.Info.LastDeployed.IsZero() {
|
||||
fmt.Fprintf(out, "LAST DEPLOYED: %s\n", res.Info.LastDeployed)
|
||||
}
|
||||
fmt.Fprintf(out, "NAMESPACE: %s\n", res.Namespace)
|
||||
fmt.Fprintf(out, "STATUS: %s\n", res.Info.Status.Code)
|
||||
|
|
@ -129,8 +128,8 @@ func PrintStatus(out io.Writer, res *hapi.GetReleaseStatusResponse) {
|
|||
if res.Info.Status.LastTestSuiteRun != nil {
|
||||
lastRun := res.Info.Status.LastTestSuiteRun
|
||||
fmt.Fprintf(out, "TEST SUITE:\n%s\n%s\n\n%s\n",
|
||||
fmt.Sprintf("Last Started: %s", timeconv.String(lastRun.StartedAt)),
|
||||
fmt.Sprintf("Last Completed: %s", timeconv.String(lastRun.CompletedAt)),
|
||||
fmt.Sprintf("Last Started: %s", lastRun.StartedAt),
|
||||
fmt.Sprintf("Last Completed: %s", lastRun.CompletedAt),
|
||||
formatTestResults(lastRun.Results))
|
||||
}
|
||||
|
||||
|
|
@ -148,8 +147,8 @@ func formatTestResults(results []*release.TestRun) string {
|
|||
n := r.Name
|
||||
s := strutil.PadRight(r.Status.String(), 10, ' ')
|
||||
i := r.Info
|
||||
ts := timeconv.String(r.StartedAt)
|
||||
tc := timeconv.String(r.CompletedAt)
|
||||
ts := r.StartedAt
|
||||
tc := r.CompletedAt
|
||||
tbl.AddRow(n, s, i, ts, tc)
|
||||
}
|
||||
return tbl.String()
|
||||
|
|
|
|||
|
|
@ -20,26 +20,22 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/helm"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
var (
|
||||
date = timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
dateString = timeconv.String(&date)
|
||||
)
|
||||
var date = time.Unix(242085845, 0)
|
||||
|
||||
func TestStatusCmd(t *testing.T) {
|
||||
tests := []releaseCase{
|
||||
{
|
||||
name: "get status of a deployed release",
|
||||
args: []string{"flummoxed-chickadee"},
|
||||
expected: outputWithStatus("DEPLOYED\n\n"),
|
||||
expected: outputWithStatus("DEPLOYED"),
|
||||
rels: []*release.Release{
|
||||
releaseMockWithStatus(&release.Status{
|
||||
Code: release.Status_DEPLOYED,
|
||||
|
|
@ -61,7 +57,7 @@ func TestStatusCmd(t *testing.T) {
|
|||
name: "get status of a deployed release with notes in json",
|
||||
args: []string{"flummoxed-chickadee"},
|
||||
flags: []string{"-o", "json"},
|
||||
expected: `{"name":"flummoxed-chickadee","info":{"status":{"code":1,"notes":"release notes"},"first_deployed":{"seconds":242085845},"last_deployed":{"seconds":242085845}}}`,
|
||||
expected: `{"name":"flummoxed-chickadee","info":{"status":{"code":1,"notes":"release notes"},"first_deployed":(.*),"last_deployed":(.*)}}`,
|
||||
rels: []*release.Release{
|
||||
releaseMockWithStatus(&release.Status{
|
||||
Code: release.Status_DEPLOYED,
|
||||
|
|
@ -96,29 +92,29 @@ func TestStatusCmd(t *testing.T) {
|
|||
name: "get status of a deployed release with test suite",
|
||||
args: []string{"flummoxed-chickadee"},
|
||||
expected: outputWithStatus(
|
||||
fmt.Sprintf("DEPLOYED\n\nTEST SUITE:\nLast Started: %s\nLast Completed: %s\n\n", dateString, dateString) +
|
||||
"DEPLOYED\n\nTEST SUITE:\nLast Started: (.*)\nLast Completed: (.*)\n\n" +
|
||||
"TEST \tSTATUS (.*)\tINFO (.*)\tSTARTED (.*)\tCOMPLETED (.*)\n" +
|
||||
fmt.Sprintf("test run 1\tSUCCESS (.*)\textra info\t%s\t%s\n", dateString, dateString) +
|
||||
fmt.Sprintf("test run 2\tFAILURE (.*)\t (.*)\t%s\t%s\n", dateString, dateString)),
|
||||
"test run 1\tSUCCESS (.*)\textra info\t(.*)\t(.*)\n" +
|
||||
"test run 2\tFAILURE (.*)\t (.*)\t(.*)\t(.*)\n"),
|
||||
rels: []*release.Release{
|
||||
releaseMockWithStatus(&release.Status{
|
||||
Code: release.Status_DEPLOYED,
|
||||
LastTestSuiteRun: &release.TestSuite{
|
||||
StartedAt: &date,
|
||||
CompletedAt: &date,
|
||||
StartedAt: date,
|
||||
CompletedAt: date,
|
||||
Results: []*release.TestRun{
|
||||
{
|
||||
Name: "test run 1",
|
||||
Status: release.TestRun_SUCCESS,
|
||||
Info: "extra info",
|
||||
StartedAt: &date,
|
||||
CompletedAt: &date,
|
||||
StartedAt: date,
|
||||
CompletedAt: date,
|
||||
},
|
||||
{
|
||||
Name: "test run 2",
|
||||
Status: release.TestRun_FAILURE,
|
||||
StartedAt: &date,
|
||||
CompletedAt: &date,
|
||||
StartedAt: date,
|
||||
CompletedAt: date,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -134,17 +130,15 @@ func TestStatusCmd(t *testing.T) {
|
|||
}
|
||||
|
||||
func outputWithStatus(status string) string {
|
||||
return fmt.Sprintf("LAST DEPLOYED: %s\nNAMESPACE: \nSTATUS: %s",
|
||||
dateString,
|
||||
status)
|
||||
return fmt.Sprintf(`LAST DEPLOYED:(.*)\nNAMESPACE: \nSTATUS: %s`, status)
|
||||
}
|
||||
|
||||
func releaseMockWithStatus(status *release.Status) *release.Release {
|
||||
return &release.Release{
|
||||
Name: "flummoxed-chickadee",
|
||||
Info: &release.Info{
|
||||
FirstDeployed: &date,
|
||||
LastDeployed: &date,
|
||||
FirstDeployed: date,
|
||||
LastDeployed: date,
|
||||
Status: status,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import (
|
|||
"k8s.io/helm/pkg/hapi/release"
|
||||
util "k8s.io/helm/pkg/releaseutil"
|
||||
"k8s.io/helm/pkg/tiller"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
tversion "k8s.io/helm/pkg/version"
|
||||
)
|
||||
|
||||
|
|
@ -180,7 +179,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
options := chartutil.ReleaseOptions{
|
||||
Name: t.releaseName,
|
||||
Time: timeconv.Now(),
|
||||
Time: time.Now(),
|
||||
Namespace: t.namespace,
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +251,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
|
|||
Config: config,
|
||||
Version: 1,
|
||||
Namespace: t.namespace,
|
||||
Info: &release.Info{LastDeployed: timeconv.Timestamp(time.Now())},
|
||||
Info: &release.Info{LastDeployed: time.Now()},
|
||||
}
|
||||
printRelease(os.Stdout, rel)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
|
||||
"k8s.io/helm/pkg/hapi/chart"
|
||||
)
|
||||
|
|
@ -336,7 +336,7 @@ func coalesceTables(dst, src map[string]interface{}) map[string]interface{} {
|
|||
// for the composition of the final values struct
|
||||
type ReleaseOptions struct {
|
||||
Name string
|
||||
Time *timestamp.Timestamp
|
||||
Time time.Time
|
||||
Namespace string
|
||||
IsUpgrade bool
|
||||
IsInstall bool
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/any"
|
||||
|
||||
kversion "k8s.io/apimachinery/pkg/version"
|
||||
|
||||
"k8s.io/helm/pkg/hapi/chart"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
"k8s.io/helm/pkg/version"
|
||||
)
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ where:
|
|||
|
||||
o := ReleaseOptions{
|
||||
Name: "Seven Voyages",
|
||||
Time: timeconv.Now(),
|
||||
Time: time.Now(),
|
||||
Namespace: "al Basrah",
|
||||
IsInstall: true,
|
||||
Revision: 5,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package release
|
||||
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
|
||||
import "time"
|
||||
|
||||
type Hook_Event int32
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ type Hook struct {
|
|||
// Events are the events that this hook fires on.
|
||||
Events []Hook_Event `json:"events,omitempty"`
|
||||
// LastRun indicates the date/time this was last run.
|
||||
LastRun *google_protobuf.Timestamp `json:"last_run,omitempty"`
|
||||
LastRun time.Time `json:"last_run,omitempty"`
|
||||
// Weight indicates the sort order for execution among similar Hook type
|
||||
Weight int32 `json:"weight,omitempty"`
|
||||
// DeletePolicies are the policies that indicate when to delete the hook
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
package release
|
||||
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
|
||||
import "time"
|
||||
|
||||
// Info describes release information.
|
||||
type Info struct {
|
||||
Status *Status `json:"status,omitempty"`
|
||||
FirstDeployed *google_protobuf.Timestamp `json:"first_deployed,omitempty"`
|
||||
LastDeployed *google_protobuf.Timestamp `json:"last_deployed,omitempty"`
|
||||
Status *Status `json:"status,omitempty"`
|
||||
FirstDeployed time.Time `json:"first_deployed,omitempty"`
|
||||
LastDeployed time.Time `json:"last_deployed,omitempty"`
|
||||
// Deleted tracks when this object was deleted.
|
||||
Deleted *google_protobuf.Timestamp `json:"deleted,omitempty"`
|
||||
Deleted time.Time `json:"deleted,omitempty"`
|
||||
// Description is human-friendly "log entry" about this release.
|
||||
Description string `json:"Description,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package release
|
||||
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
|
||||
import "time"
|
||||
|
||||
type TestRun_Status int32
|
||||
|
||||
|
|
@ -29,9 +29,9 @@ func (x TestRun_Status) String() string {
|
|||
}
|
||||
|
||||
type TestRun struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Status TestRun_Status `json:"status,omitempty"`
|
||||
Info string `json:"info,omitempty"`
|
||||
StartedAt *google_protobuf.Timestamp `json:"started_at,omitempty"`
|
||||
CompletedAt *google_protobuf.Timestamp `json:"completed_at,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Status TestRun_Status `json:"status,omitempty"`
|
||||
Info string `json:"info,omitempty"`
|
||||
StartedAt time.Time `json:"started_at,omitempty"`
|
||||
CompletedAt time.Time `json:"completed_at,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package release
|
||||
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
|
||||
import "time"
|
||||
|
||||
// TestSuite comprises of the last run of the pre-defined test suite of a release version
|
||||
type TestSuite struct {
|
||||
// StartedAt indicates the date/time this test suite was kicked off
|
||||
StartedAt *google_protobuf.Timestamp `json:"started_at,omitempty"`
|
||||
StartedAt time.Time `json:"started_at,omitempty"`
|
||||
// CompletedAt indicates the date/time this test suite was completed
|
||||
CompletedAt *google_protobuf.Timestamp `json:"completed_at,omitempty"`
|
||||
CompletedAt time.Time `json:"completed_at,omitempty"`
|
||||
// Results are the results of each segment of the test
|
||||
Results []*TestRun `json:"results,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"time"
|
||||
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/chart"
|
||||
|
|
@ -188,7 +187,7 @@ type MockReleaseOptions struct {
|
|||
|
||||
// ReleaseMock creates a mock release object based on options set by MockReleaseOptions. This function should typically not be used outside of testing.
|
||||
func ReleaseMock(opts *MockReleaseOptions) *release.Release {
|
||||
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
date := time.Unix(242085845, 0)
|
||||
|
||||
name := opts.Name
|
||||
if name == "" {
|
||||
|
|
@ -226,8 +225,8 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release {
|
|||
return &release.Release{
|
||||
Name: name,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: &date,
|
||||
LastDeployed: &date,
|
||||
FirstDeployed: date,
|
||||
LastDeployed: date,
|
||||
Status: &release.Status{Code: scode},
|
||||
Description: "Release mock",
|
||||
},
|
||||
|
|
@ -241,7 +240,7 @@ func ReleaseMock(opts *MockReleaseOptions) *release.Release {
|
|||
Kind: "Job",
|
||||
Path: "pre-install-hook.yaml",
|
||||
Manifest: MockHookTemplate,
|
||||
LastRun: &date,
|
||||
LastRun: date,
|
||||
Events: []release.Hook_Event{release.Hook_PRE_INSTALL},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
|
||||
|
|
@ -28,7 +29,6 @@ import (
|
|||
"k8s.io/helm/pkg/engine"
|
||||
cpb "k8s.io/helm/pkg/hapi/chart"
|
||||
"k8s.io/helm/pkg/lint/support"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
tversion "k8s.io/helm/pkg/version"
|
||||
)
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func Templates(linter *support.Linter, values []byte, namespace string, strict b
|
|||
return
|
||||
}
|
||||
|
||||
options := chartutil.ReleaseOptions{Name: "testRelease", Time: timeconv.Now(), Namespace: namespace}
|
||||
options := chartutil.ReleaseOptions{Name: "testRelease", Time: time.Now(), Namespace: namespace}
|
||||
caps := &chartutil.Capabilities{
|
||||
APIVersions: chartutil.DefaultVersionSet,
|
||||
KubeVersion: chartutil.DefaultKubeVersion,
|
||||
|
|
|
|||
|
|
@ -19,21 +19,20 @@ package releasetesting
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/hooks"
|
||||
util "k8s.io/helm/pkg/releaseutil"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// TestSuite what tests are run, results, and metadata
|
||||
type TestSuite struct {
|
||||
StartedAt *timestamp.Timestamp
|
||||
CompletedAt *timestamp.Timestamp
|
||||
StartedAt time.Time
|
||||
CompletedAt time.Time
|
||||
TestManifests []string
|
||||
Results []*release.TestRun
|
||||
}
|
||||
|
|
@ -55,7 +54,7 @@ func NewTestSuite(rel *release.Release) *TestSuite {
|
|||
|
||||
// Run executes tests in a test suite and stores a result within a given environment
|
||||
func (ts *TestSuite) Run(env *Environment) error {
|
||||
ts.StartedAt = timeconv.Now()
|
||||
ts.StartedAt = time.Now()
|
||||
|
||||
if len(ts.TestManifests) == 0 {
|
||||
// TODO: make this better, adding test run status on test suite is weird
|
||||
|
|
@ -68,7 +67,7 @@ func (ts *TestSuite) Run(env *Environment) error {
|
|||
return err
|
||||
}
|
||||
|
||||
test.result.StartedAt = timeconv.Now()
|
||||
test.result.StartedAt = time.Now()
|
||||
if err := env.streamRunning(test.result.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -104,11 +103,11 @@ func (ts *TestSuite) Run(env *Environment) error {
|
|||
}
|
||||
}
|
||||
|
||||
test.result.CompletedAt = timeconv.Now()
|
||||
test.result.CompletedAt = time.Now()
|
||||
ts.Results = append(ts.Results, test.result)
|
||||
}
|
||||
|
||||
ts.CompletedAt = timeconv.Now()
|
||||
ts.CompletedAt = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
|
|
@ -89,10 +88,10 @@ func TestRun(t *testing.T) {
|
|||
for range ch { // drain
|
||||
}
|
||||
|
||||
if ts.StartedAt == nil {
|
||||
if ts.StartedAt.IsZero() {
|
||||
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt)
|
||||
}
|
||||
if ts.CompletedAt == nil {
|
||||
if ts.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
|
||||
}
|
||||
if len(ts.Results) != 2 {
|
||||
|
|
@ -100,10 +99,10 @@ func TestRun(t *testing.T) {
|
|||
}
|
||||
|
||||
result := ts.Results[0]
|
||||
if result.StartedAt == nil {
|
||||
if result.StartedAt.IsZero() {
|
||||
t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt)
|
||||
}
|
||||
if result.CompletedAt == nil {
|
||||
if result.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt)
|
||||
}
|
||||
if result.Name != "finding-nemo" {
|
||||
|
|
@ -113,10 +112,10 @@ func TestRun(t *testing.T) {
|
|||
t.Errorf("Expected test result to be successful, got: %v", result.Status)
|
||||
}
|
||||
result2 := ts.Results[1]
|
||||
if result2.StartedAt == nil {
|
||||
if result2.StartedAt.IsZero() {
|
||||
t.Errorf("Expected test StartedAt to not be nil. Got: %v", result2.StartedAt)
|
||||
}
|
||||
if result2.CompletedAt == nil {
|
||||
if result2.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result2.CompletedAt)
|
||||
}
|
||||
if result2.Name != "gold-rush" {
|
||||
|
|
@ -145,10 +144,10 @@ func TestRunEmptyTestSuite(t *testing.T) {
|
|||
if msg.Msg != "No Tests Found" {
|
||||
t.Errorf("Expected message 'No Tests Found', Got: %v", msg.Msg)
|
||||
}
|
||||
if ts.StartedAt == nil {
|
||||
if ts.StartedAt.IsZero() {
|
||||
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt)
|
||||
}
|
||||
if ts.CompletedAt == nil {
|
||||
if ts.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
|
||||
}
|
||||
if len(ts.Results) != 0 {
|
||||
|
|
@ -174,11 +173,11 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) {
|
|||
for range ch { // drain
|
||||
}
|
||||
|
||||
if ts.StartedAt == nil {
|
||||
if ts.StartedAt.IsZero() {
|
||||
t.Errorf("Expected StartedAt to not be nil. Got: %v", ts.StartedAt)
|
||||
}
|
||||
|
||||
if ts.CompletedAt == nil {
|
||||
if ts.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected CompletedAt to not be nil. Got: %v", ts.CompletedAt)
|
||||
}
|
||||
|
||||
|
|
@ -187,11 +186,11 @@ func TestRunSuccessWithTestFailureHook(t *testing.T) {
|
|||
}
|
||||
|
||||
result := ts.Results[0]
|
||||
if result.StartedAt == nil {
|
||||
if result.StartedAt.IsZero() {
|
||||
t.Errorf("Expected test StartedAt to not be nil. Got: %v", result.StartedAt)
|
||||
}
|
||||
|
||||
if result.CompletedAt == nil {
|
||||
if result.CompletedAt.IsZero() {
|
||||
t.Errorf("Expected test CompletedAt to not be nil. Got: %v", result.CompletedAt)
|
||||
}
|
||||
|
||||
|
|
@ -226,12 +225,12 @@ func chartStub() *chart.Chart {
|
|||
}
|
||||
|
||||
func releaseStub() *release.Release {
|
||||
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
date := time.Unix(242085845, 0)
|
||||
return &release.Release{
|
||||
Name: "lost-fish",
|
||||
Info: &release.Info{
|
||||
FirstDeployed: &date,
|
||||
LastDeployed: &date,
|
||||
FirstDeployed: date,
|
||||
LastDeployed: date,
|
||||
Status: &release.Status{Code: release.Status_DEPLOYED},
|
||||
Description: "a release stub",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ func SortByDate(list []*rspb.Release) {
|
|||
s := &sorter{list: list}
|
||||
|
||||
s.less = func(i, j int) bool {
|
||||
ti := s.list[i].Info.LastDeployed.Seconds
|
||||
tj := s.list[j].Info.LastDeployed.Seconds
|
||||
ti := s.list[i].Info.LastDeployed.Second()
|
||||
tj := s.list[j].Info.LastDeployed.Second()
|
||||
return ti < tj
|
||||
}
|
||||
sort.Sort(s)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"time"
|
||||
|
||||
rspb "k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// note: this test data is shared with filter_test.go.
|
||||
|
|
@ -34,7 +33,7 @@ var releases = []*rspb.Release{
|
|||
}
|
||||
|
||||
func tsRelease(name string, vers int32, dur time.Duration, code rspb.Status_Code) *rspb.Release {
|
||||
tmsp := timeconv.Timestamp(time.Now().Add(time.Duration(dur)))
|
||||
tmsp := time.Now().Add(time.Duration(dur))
|
||||
info := &rspb.Info{Status: &rspb.Status{Code: code}, LastDeployed: tmsp}
|
||||
return &rspb.Release{
|
||||
Name: name,
|
||||
|
|
@ -65,8 +64,8 @@ func TestSortByDate(t *testing.T) {
|
|||
SortByDate(releases)
|
||||
|
||||
check(t, "ByDate", func(i, j int) bool {
|
||||
ti := releases[i].Info.LastDeployed.Seconds
|
||||
tj := releases[j].Info.LastDeployed.Seconds
|
||||
ti := releases[i].Info.LastDeployed.Second()
|
||||
tj := releases[j].Info.LastDeployed.Second()
|
||||
return ti < tj
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/hooks"
|
||||
relutil "k8s.io/helm/pkg/releaseutil"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// InstallRelease installs a release and stores the release record.
|
||||
|
|
@ -69,7 +69,7 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas
|
|||
}
|
||||
|
||||
revision := 1
|
||||
ts := timeconv.Now()
|
||||
ts := time.Now()
|
||||
options := chartutil.ReleaseOptions{
|
||||
Name: name,
|
||||
Time: ts,
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ func TestInstallRelease_DryRun(t *testing.T) {
|
|||
t.Fatalf("Expected 1 hook, got %d", l)
|
||||
}
|
||||
|
||||
if res.Hooks[0].LastRun != nil {
|
||||
if !res.Hooks[0].LastRun.IsZero() {
|
||||
t.Error("Expected hook to not be marked as run.")
|
||||
}
|
||||
|
||||
|
|
@ -289,8 +289,8 @@ func TestInstallRelease_NoHooks(t *testing.T) {
|
|||
t.Errorf("Failed install: %s", err)
|
||||
}
|
||||
|
||||
if hl := res.Hooks[0].LastRun; hl != nil {
|
||||
t.Errorf("Expected that no hooks were run. Got %d", hl)
|
||||
if !res.Hooks[0].LastRun.IsZero() {
|
||||
t.Errorf("Expected that no hooks were run. Got %s", res.Hooks[0].LastRun)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ package tiller
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/hooks"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// RollbackRelease rolls back to a previous version of the given release.
|
||||
|
|
@ -93,7 +93,7 @@ func (s *ReleaseServer) prepareRollback(req *hapi.RollbackReleaseRequest) (*rele
|
|||
Config: previousRelease.Config,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: currentRelease.Info.FirstDeployed,
|
||||
LastDeployed: timeconv.Now(),
|
||||
LastDeployed: time.Now(),
|
||||
Status: &release.Status{
|
||||
Code: release.Status_PENDING_ROLLBACK,
|
||||
Notes: previousRelease.Info.Status.Notes,
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ func TestRollbackReleaseNoHooks(t *testing.T) {
|
|||
t.Fatalf("Failed rollback: %s", err)
|
||||
}
|
||||
|
||||
if hl := res.Hooks[0].LastRun; hl != nil {
|
||||
t.Errorf("Expected that no hooks were run. Got %d", hl)
|
||||
if hl := res.Hooks[0].LastRun; !hl.IsZero() {
|
||||
t.Errorf("Expected that no hooks were run. Got %s", hl)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/technosophos/moniker"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
|
@ -38,7 +39,6 @@ import (
|
|||
"k8s.io/helm/pkg/kube"
|
||||
relutil "k8s.io/helm/pkg/releaseutil"
|
||||
"k8s.io/helm/pkg/tiller/environment"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
"k8s.io/helm/pkg/version"
|
||||
)
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ func (s *ReleaseServer) execHook(hs []*release.Hook, name, namespace, hook strin
|
|||
if err := s.deleteHookIfShouldBeDeletedByDeletePolicy(h, hooks.HookSucceeded, name, namespace, hook, s.env.KubeClient); err != nil {
|
||||
return err
|
||||
}
|
||||
h.LastRun = timeconv.Now()
|
||||
h.LastRun = time.Now()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
|
|
@ -223,12 +222,12 @@ func releaseStub() *release.Release {
|
|||
}
|
||||
|
||||
func namedReleaseStub(name string, status release.Status_Code) *release.Release {
|
||||
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
date := time.Unix(242085845, 0)
|
||||
return &release.Release{
|
||||
Name: name,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: &date,
|
||||
LastDeployed: &date,
|
||||
FirstDeployed: date,
|
||||
LastDeployed: date,
|
||||
Status: &release.Status{Code: status},
|
||||
Description: "Named Release Stub",
|
||||
},
|
||||
|
|
@ -260,14 +259,14 @@ func namedReleaseStub(name string, status release.Status_Code) *release.Release
|
|||
}
|
||||
|
||||
func upgradeReleaseVersion(rel *release.Release) *release.Release {
|
||||
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
date := time.Unix(242085845, 0)
|
||||
|
||||
rel.Info.Status.Code = release.Status_SUPERSEDED
|
||||
return &release.Release{
|
||||
Name: rel.Name,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: rel.Info.FirstDeployed,
|
||||
LastDeployed: &date,
|
||||
LastDeployed: date,
|
||||
Status: &release.Status{Code: release.Status_DEPLOYED},
|
||||
},
|
||||
Chart: rel.Chart,
|
||||
|
|
@ -367,12 +366,12 @@ func releaseWithKeepStub(rlsName string) *release.Release {
|
|||
},
|
||||
}
|
||||
|
||||
date := timestamp.Timestamp{Seconds: 242085845, Nanos: 0}
|
||||
date := time.Unix(242085845, 0)
|
||||
return &release.Release{
|
||||
Name: rlsName,
|
||||
Info: &release.Info{
|
||||
FirstDeployed: &date,
|
||||
LastDeployed: &date,
|
||||
FirstDeployed: date,
|
||||
LastDeployed: date,
|
||||
Status: &release.Status{Code: release.Status_DEPLOYED},
|
||||
},
|
||||
Chart: ch,
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ package tiller
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/hooks"
|
||||
relutil "k8s.io/helm/pkg/releaseutil"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// UninstallRelease deletes all of the resources associated with this release, and marks the release DELETED.
|
||||
|
|
@ -61,7 +61,7 @@ func (s *ReleaseServer) UninstallRelease(req *hapi.UninstallReleaseRequest) (*ha
|
|||
|
||||
s.Log("uninstall: Deleting %s", req.Name)
|
||||
rel.Info.Status.Code = release.Status_DELETING
|
||||
rel.Info.Deleted = timeconv.Now()
|
||||
rel.Info.Deleted = time.Now()
|
||||
rel.Info.Description = "Deletion in progress (or silently failed)"
|
||||
res := &hapi.UninstallReleaseResponse{Release: rel}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ func TestUninstallRelease(t *testing.T) {
|
|||
t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code)
|
||||
}
|
||||
|
||||
if res.Release.Hooks[0].LastRun.Seconds == 0 {
|
||||
if res.Release.Hooks[0].LastRun.IsZero() {
|
||||
t.Error("Expected LastRun to be greater than zero.")
|
||||
}
|
||||
|
||||
if res.Release.Info.Deleted.Seconds <= 0 {
|
||||
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds)
|
||||
if res.Release.Info.Deleted.Second() <= 0 {
|
||||
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second())
|
||||
}
|
||||
|
||||
if res.Release.Info.Description != "Deletion complete" {
|
||||
|
|
@ -84,8 +84,8 @@ func TestUninstallPurgeRelease(t *testing.T) {
|
|||
t.Errorf("Expected status code to be DELETED, got %d", res.Release.Info.Status.Code)
|
||||
}
|
||||
|
||||
if res.Release.Info.Deleted.Seconds <= 0 {
|
||||
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Seconds)
|
||||
if res.Release.Info.Deleted.Second() <= 0 {
|
||||
t.Errorf("Expected valid UNIX date, got %d", res.Release.Info.Deleted.Second())
|
||||
}
|
||||
rels, err := rs.GetHistory(&hapi.GetHistoryRequest{Name: "angry-panda"})
|
||||
if err != nil {
|
||||
|
|
@ -166,7 +166,7 @@ func TestUninstallReleaseNoHooks(t *testing.T) {
|
|||
}
|
||||
|
||||
// The default value for a protobuf timestamp is nil.
|
||||
if res.Release.Hooks[0].LastRun != nil {
|
||||
t.Errorf("Expected LastRun to be zero, got %d.", res.Release.Hooks[0].LastRun.Seconds)
|
||||
if !res.Release.Hooks[0].LastRun.IsZero() {
|
||||
t.Errorf("Expected LastRun to be zero, got %s.", res.Release.Hooks[0].LastRun)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ package tiller
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/helm/pkg/chartutil"
|
||||
"k8s.io/helm/pkg/hapi"
|
||||
"k8s.io/helm/pkg/hapi/release"
|
||||
"k8s.io/helm/pkg/hooks"
|
||||
"k8s.io/helm/pkg/timeconv"
|
||||
)
|
||||
|
||||
// UpdateRelease takes an existing release and new information, and upgrades the release.
|
||||
|
|
@ -93,7 +93,7 @@ func (s *ReleaseServer) prepareUpdate(req *hapi.UpdateReleaseRequest) (*release.
|
|||
// the release object.
|
||||
revision := lastRelease.Version + 1
|
||||
|
||||
ts := timeconv.Now()
|
||||
ts := time.Now()
|
||||
options := chartutil.ReleaseOptions{
|
||||
Name: req.Name,
|
||||
Time: ts,
|
||||
|
|
@ -172,7 +172,7 @@ func (s *ReleaseServer) performUpdateForce(req *hapi.UpdateReleaseRequest) (*rel
|
|||
// From here on out, the release is considered to be in Status_DELETING or Status_DELETED
|
||||
// state. There is no turning back.
|
||||
oldRelease.Info.Status.Code = release.Status_DELETING
|
||||
oldRelease.Info.Deleted = timeconv.Now()
|
||||
oldRelease.Info.Deleted = time.Now()
|
||||
oldRelease.Info.Description = "Deletion in progress (or silently failed)"
|
||||
s.recordRelease(oldRelease, true)
|
||||
|
||||
|
|
|
|||
|
|
@ -397,8 +397,8 @@ func TestUpdateReleaseNoHooks(t *testing.T) {
|
|||
t.Fatalf("Failed updated: %s", err)
|
||||
}
|
||||
|
||||
if hl := res.Hooks[0].LastRun; hl != nil {
|
||||
t.Errorf("Expected that no hooks were run. Got %d", hl)
|
||||
if hl := res.Hooks[0].LastRun; !hl.IsZero() {
|
||||
t.Errorf("Expected that no hooks were run. Got %s", hl)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 timeconv contains utilities for converting time.
|
||||
|
||||
The gRPC/Protobuf libraries contain time implementations that require conversion
|
||||
to and from Go times. This library provides utilities and convenience functions
|
||||
for performing conversions.
|
||||
*/
|
||||
package timeconv // import "k8s.io/helm/pkg/timeconv"
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 timeconv
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
)
|
||||
|
||||
// Now creates a timestamp.Timestamp representing the current time.
|
||||
func Now() *timestamp.Timestamp {
|
||||
return Timestamp(time.Now())
|
||||
}
|
||||
|
||||
// Timestamp converts a time.Time to a protobuf *timestamp.Timestamp.
|
||||
func Timestamp(t time.Time) *timestamp.Timestamp {
|
||||
return ×tamp.Timestamp{
|
||||
Seconds: t.Unix(),
|
||||
Nanos: int32(t.Nanosecond()),
|
||||
}
|
||||
}
|
||||
|
||||
// Time converts a protobuf *timestamp.Timestamp to a time.Time.
|
||||
func Time(ts *timestamp.Timestamp) time.Time {
|
||||
return time.Unix(ts.Seconds, int64(ts.Nanos))
|
||||
}
|
||||
|
||||
// Format formats a *timestamp.Timestamp into a string.
|
||||
//
|
||||
// This follows the rules for time.Time.Format().
|
||||
func Format(ts *timestamp.Timestamp, layout string) string {
|
||||
return Time(ts).Format(layout)
|
||||
}
|
||||
|
||||
// String formats the timestamp into a user-friendly string.
|
||||
//
|
||||
// Currently, this uses the 'time.ANSIC' format string, but there is no guarantee
|
||||
// that this will not change.
|
||||
//
|
||||
// This is a convenience function for formatting timestamps for user display.
|
||||
func String(ts *timestamp.Timestamp) string {
|
||||
return Format(ts, time.ANSIC)
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 timeconv
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNow(t *testing.T) {
|
||||
now := time.Now()
|
||||
ts := Now()
|
||||
var drift int64 = 5
|
||||
if ts.Seconds < int64(now.Second())-drift {
|
||||
t.Errorf("Unexpected time drift: %d", ts.Seconds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimestamp(t *testing.T) {
|
||||
now := time.Now()
|
||||
ts := Timestamp(now)
|
||||
|
||||
if now.Unix() != ts.Seconds {
|
||||
t.Errorf("Unexpected time drift: %d to %d", now.Second(), ts.Seconds)
|
||||
}
|
||||
|
||||
if now.Nanosecond() != int(ts.Nanos) {
|
||||
t.Errorf("Unexpected nano drift: %d to %d", now.Nanosecond(), ts.Nanos)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
nowts := Now()
|
||||
now := Time(nowts)
|
||||
|
||||
if now.Unix() != nowts.Seconds {
|
||||
t.Errorf("Unexpected time drift %d", now.Unix())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormat(t *testing.T) {
|
||||
now := time.Now()
|
||||
nowts := Timestamp(now)
|
||||
|
||||
if now.Format(time.ANSIC) != Format(nowts, time.ANSIC) {
|
||||
t.Error("Format mismatch")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue