Use var for timestamper, instead of adding as a struct field

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/5077/head
Matt Butcher 7 years ago
parent 59df9596eb
commit 4b070af144
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -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)

@ -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

@ -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 {

@ -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

Loading…
Cancel
Save