(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestRunJavaScript(t *testing.T) { |
| 31 | Convey("Test RunJavascript expect string", t, func() { |
| 32 | script := `Path = "test/" + User.Name;` |
| 33 | in := map[string]interface{}{ |
| 34 | "User": map[string]interface{}{ |
| 35 | "Name": "john", |
| 36 | }, |
| 37 | } |
| 38 | out := map[string]interface{}{ |
| 39 | "Path": "", |
| 40 | } |
| 41 | e := RunJavaScript(context.Background(), script, in, out) |
| 42 | So(e, ShouldBeNil) |
| 43 | So(out["Path"], ShouldEqual, "test/john") |
| 44 | }) |
| 45 | Convey("Test RunJavascript expect bool", t, func() { |
| 46 | script := `bVal = User.Name === "john";` |
| 47 | in := map[string]interface{}{ |
| 48 | "User": map[string]interface{}{ |
| 49 | "Name": "john", |
| 50 | }, |
| 51 | } |
| 52 | out := map[string]interface{}{ |
| 53 | "bVal": false, |
| 54 | } |
| 55 | e := RunJavaScript(context.Background(), script, in, out) |
| 56 | So(e, ShouldBeNil) |
| 57 | So(out["bVal"], ShouldBeTrue) |
| 58 | }) |
| 59 | // Not triggering error anymore - out["bVal"] is simply replaced by a boolean |
| 60 | SkipConvey("Test unexpected output format", t, func() { |
| 61 | script := `bVal = User.Name === "john";` |
| 62 | in := map[string]interface{}{ |
| 63 | "User": map[string]interface{}{ |
| 64 | "Name": "john", |
| 65 | }, |
| 66 | } |
| 67 | out := map[string]interface{}{ |
| 68 | "bVal": 18, |
| 69 | } |
| 70 | e := RunJavaScript(context.Background(), script, in, out) |
| 71 | So(e, ShouldNotBeNil) |
| 72 | }) |
| 73 | Convey("Test invalid Javascript", t, func() { |
| 74 | script := `Value = User/Name === john;` |
| 75 | in := map[string]interface{}{ |
| 76 | "User": map[string]interface{}{ |
| 77 | "Name": "john", |
| 78 | }, |
| 79 | } |
| 80 | out := map[string]interface{}{ |
| 81 | "Value": false, |
| 82 | } |
| 83 | e := RunJavaScript(context.Background(), script, in, out) |
| 84 | So(e, ShouldNotBeNil) |
| 85 | }) |
| 86 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…