diff --git a/engine/env.go b/engine/env.go index a671f13c6b..c6c673271e 100644 --- a/engine/env.go +++ b/engine/env.go @@ -189,7 +189,10 @@ func (decoder *Decoder) Decode() (*Env, error) { // is returned. func (env *Env) Decode(src io.Reader) error { m := make(map[string]interface{}) - if err := json.NewDecoder(src).Decode(&m); err != nil { + d := json.NewDecoder(src) + // We need this or we'll lose data when we decode int64 in json + d.UseNumber() + if err := d.Decode(&m); err != nil { return err } for k, v := range m { diff --git a/engine/env_test.go b/engine/env_test.go index 11e930cad1..1398275b2b 100644 --- a/engine/env_test.go +++ b/engine/env_test.go @@ -78,6 +78,26 @@ func TestSetenv(t *testing.T) { } } +func TestDecodeEnv(t *testing.T) { + job := mkJob(t, "dummy") + type tmp struct { + Id1 int64 + Id2 int64 + } + body := []byte("{\"tags\":{\"Id1\":123, \"Id2\":1234567}}") + if err := job.DecodeEnv(bytes.NewBuffer(body)); err != nil { + t.Fatalf("DecodeEnv failed: %v", err) + } + mytag := tmp{} + if val := job.GetenvJson("tags", &mytag); val != nil { + t.Fatalf("GetenvJson returns incorrect value: %s", val) + } + + if mytag.Id1 != 123 || mytag.Id2 != 1234567 { + t.Fatal("Get wrong values set by job.DecodeEnv") + } +} + func TestSetenvBool(t *testing.T) { job := mkJob(t, "dummy") job.SetenvBool("foo", true)