Skip to content

Commit d32fd44

Browse files
authored
Fix unmarshal bug for poll interval in elasticreload (#34)
* Properly unmarshal elasticreloadsettings
1 parent faa7cc3 commit d32fd44

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

helpers/timeduration_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package helpers
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestMarshalTimeDuration(t *testing.T) {
9+
td := TimeDuration(2000000000)
10+
expected := "\"1s\""
11+
err := td.UnmarshalJSON([]byte(expected))
12+
if err != nil {
13+
t.Errorf("got error during unmarshal <%s>", err)
14+
}
15+
json, err := td.MarshalJSON()
16+
if err != nil {
17+
t.Errorf("got error during marshal <%s>", err)
18+
}
19+
if fmt.Sprintf("%s", json) != expected {
20+
t.Errorf("expected<%s> got %s", expected, json)
21+
}
22+
}

scenario/elasticreload.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import (
1818
type (
1919
// ElasticReloadCore Currently used ElasticReloadCore (as opposed to deprecated settings)
2020
ElasticReloadCore struct {
21-
session.AppSelection
2221
// PollInterval time in-between polling for reload status
2322
PollInterval helpers.TimeDuration `json:"pollinterval" displayname:"Poll interval" doc-key:"elasticreload.pollinterval"`
2423
}
2524

2625
//ElasticReloadSettings specify app to reload
2726
ElasticReloadSettings struct {
27+
session.AppSelection
2828
ElasticReloadCore
2929
}
3030

@@ -66,7 +66,11 @@ func (settings *ElasticReloadSettings) UnmarshalJSON(arg []byte) error {
6666
if err := jsonit.Unmarshal(arg, &core); err != nil {
6767
return errors.Wrapf(err, "failed to unmarshal action<%s>", ActionElasticReload)
6868
}
69-
*settings = ElasticReloadSettings{core}
69+
var appSelection session.AppSelection
70+
if err := jsonit.Unmarshal(arg, &appSelection); err != nil {
71+
return errors.Wrapf(err, "failed to unmarshal action<%s>", ActionOpenApp)
72+
}
73+
*settings = ElasticReloadSettings{appSelection, core}
7074
return nil
7175
}
7276

0 commit comments

Comments
 (0)