parent
45839d68ec
commit
e9de6ca2c0
2 changed files with 5 additions and 2 deletions
|
@ -166,14 +166,16 @@ func vmJoin(vm *otto.Otto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func vmToJSON(vm *otto.Otto) {
|
func vmToJSON(vm *otto.Otto) {
|
||||||
_ = vm.Set("toJSON", func(o interface{}) string {
|
toJSON := func(o interface{}) string {
|
||||||
rtn, err := json.MarshalIndent(o, "", " ")
|
rtn, err := json.MarshalIndent(o, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Unable to marsal: %v", err)
|
logrus.Errorf("Unable to marsal: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return string(rtn)
|
return string(rtn)
|
||||||
})
|
}
|
||||||
|
_ = vm.Set("toJSON", toJSON)
|
||||||
|
_ = vm.Set("toJson", toJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
|
func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ func TestEvaluate(t *testing.T) {
|
||||||
{"join(['hello','mona','the'],'octocat')", "hello mona the octocat", ""},
|
{"join(['hello','mona','the'],'octocat')", "hello mona the octocat", ""},
|
||||||
{"join('hello','mona')", "hello mona", ""},
|
{"join('hello','mona')", "hello mona", ""},
|
||||||
{"toJSON({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
|
{"toJSON({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
|
||||||
|
{"toJson({'foo':'bar'})", "{\n \"foo\": \"bar\"\n}", ""},
|
||||||
{"hashFiles('**/package-lock.json')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
|
{"hashFiles('**/package-lock.json')", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
|
||||||
{"success()", "true", ""},
|
{"success()", "true", ""},
|
||||||
{"failure()", "false", ""},
|
{"failure()", "false", ""},
|
||||||
|
|
Loading…
Reference in a new issue