From 4b070af1443e6ff65262925a97dd5c0558367f69 Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Mon, 7 Jan 2019 17:30:47 -0700 Subject: [PATCH] Use var for timestamper, instead of adding as a struct field Signed-off-by: Matt Butcher --- cmd/helm/helm_test.go | 13 ++++++++----- cmd/helm/install.go | 15 +-------------- cmd/helm/list.go | 2 -- pkg/action/action.go | 17 ++++++----------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 61d6ff318..12920a39b 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -43,12 +43,16 @@ import ( // base temp directory var testingDir string +func testTimestamper() time.Time { return time.Unix(242085845, 0).UTC() } + func init() { var err error testingDir, err = ioutil.TempDir(testingDir, "helm") if err != nil { panic(err) } + + action.Timestamper = testTimestamper } func TestMain(m *testing.M) { @@ -122,11 +126,10 @@ func executeActionCommandC(store *storage.Storage, cmd string) (*cobra.Command, buf := new(bytes.Buffer) actionConfig := &action.Configuration{ - Releases: store, - KubeClient: &environment.PrintingKubeClient{Out: ioutil.Discard}, - Discovery: fake.NewSimpleClientset().Discovery(), - Log: func(format string, v ...interface{}) {}, - Timestamper: func() time.Time { return time.Unix(242085845, 0).UTC() }, + Releases: store, + KubeClient: &environment.PrintingKubeClient{Out: ioutil.Discard}, + Discovery: fake.NewSimpleClientset().Discovery(), + Log: func(format string, v ...interface{}) {}, } root := newRootCmd(nil, actionConfig, buf, args) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 39b42d5f2..a0b23a829 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -270,23 +270,10 @@ func (o *installOptions) run(out io.Writer) error { } o.printRelease(out, rel) - // If this is a dry run, we can't display status. - if o.dryRun { - return nil - } - - // Print the status like status command does - /* - status, err := o.client.ReleaseStatus(rel.Name, 0) - if err != nil { - return err - } - PrintStatus(out, status) - */ return nil } -// printRelease prints info about a release if the Debug is true. +// printRelease prints info about a release func (o *installOptions) printRelease(out io.Writer, rel *release.Release) { if rel == nil { return diff --git a/cmd/helm/list.go b/cmd/helm/list.go index ac137f282..280d4585a 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -74,8 +74,6 @@ type listOptions struct { superseded bool // --superseded filter string - - //client helm.Interface } func newListCmd(actionConfig *action.Configuration, out io.Writer) *cobra.Command { diff --git a/pkg/action/action.go b/pkg/action/action.go index dd9e5eef0..ad417cc08 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -29,15 +29,15 @@ import ( "k8s.io/helm/pkg/version" ) -// Timestamper is a function that can provide a timestamp. +// Timestamper is a function capable of producing a timestamp.Timestamper. // -// If this is not set, the `time.Now()` function is used to generate -// timestamps. This may be overridden for testing. -type Timestamper func() time.Time +// By default, this is a time.Time function. This can be overridden for testing, +// though, so that timestamps are predictable. +var Timestamper = time.Now // Configuration injects the dependencies that all actions share. type Configuration struct { - //engine Engine + // Discovery contains a discovery client Discovery discovery.DiscoveryInterface // Releases stores records of releases. @@ -46,8 +46,6 @@ type Configuration struct { KubeClient environment.KubeClient Log func(string, ...interface{}) - - Timestamper Timestamper } // capabilities builds a Capabilities from discovery information. @@ -72,10 +70,7 @@ func (c *Configuration) capabilities() (*chartutil.Capabilities, error) { // If the configuration has a Timestamper on it, that will be used. // Otherwise, this will use time.Now(). func (c *Configuration) Now() time.Time { - if c.Timestamper != nil { - return c.Timestamper() - } - return time.Now() + return Timestamper() } // GetVersionSet retrieves a set of available k8s API versions