Shim bare numbers into duration strings [#39]
Helm2's --timeout took a number of seconds, rather than the ParseDuration-compatible string that helm3 uses. For backward- compatibility, update a bare number into a duration string.
This commit is contained in:
@@ -4,8 +4,11 @@ import (
|
||||
"fmt"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
"io"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var justNumbers = regexp.MustCompile(`^\d+$`)
|
||||
|
||||
// The Config struct captures the `settings` and `environment` blocks in the application's drone
|
||||
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
|
||||
// config key, prefixed with `PLUGIN_`. Config from the `environment` block is uppercased, but does
|
||||
@@ -62,6 +65,10 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if justNumbers.MatchString(cfg.Timeout) {
|
||||
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
|
||||
}
|
||||
|
||||
if cfg.Debug && cfg.Stderr != nil {
|
||||
cfg.logDebug()
|
||||
}
|
||||
|
||||
@@ -106,6 +106,13 @@ func (suite *ConfigTestSuite) TestNewConfigWithConflictingVariables() {
|
||||
suite.Equal("2m30s", cfg.Timeout)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||
suite.setenv("PLUGIN_TIMEOUT", "42")
|
||||
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal("42s", cfg.Timeout)
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
||||
stdout := &strings.Builder{}
|
||||
stderr := &strings.Builder{}
|
||||
|
||||
Reference in New Issue
Block a user