Skip to content

Commit 78ffea9

Browse files
committed
Fix truth value for output
1 parent a0b386d commit 78ffea9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

internal/app/starlark_type/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (o Output) Freeze() {
4545
}
4646

4747
func (o Output) Truth() starlark.Bool {
48-
return o.Err != ""
48+
return o.Err == ""
4949
}
5050

5151
func (o Output) Hash() (uint32, error) {

internal/app/tests/basic_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,20 @@ def h22(req):
595595
def h3(req):
596596
v = f3()
597597
return v.value["k"]
598+
def h4(req):
599+
ret = ace.output(error="h4error")
600+
if ret:
601+
return "ok"
602+
else:
603+
return "fail"
598604
599605
app = ace.app("testApp",
600606
routes = [
601607
ace.api("/api1", handler=h1),
602608
ace.api("/api2", handler=h2),
603609
ace.api("/api22", handler=h22),
604-
ace.api("/api3", handler=h3)
610+
ace.api("/api3", handler=h3),
611+
ace.api("/api4", handler=h4)
605612
]
606613
)
607614
`,
@@ -638,4 +645,11 @@ app = ace.app("testApp",
638645

639646
testutil.AssertEqualsInt(t, "code", 200, response.Code)
640647
testutil.AssertStringContains(t, response.Body.String(), "\"v\"")
648+
649+
request = httptest.NewRequest("GET", "/api4", nil)
650+
response = httptest.NewRecorder()
651+
a.ServeHTTP(response, request)
652+
653+
testutil.AssertEqualsInt(t, "code", 200, response.Code)
654+
testutil.AssertStringContains(t, response.Body.String(), "\"fail\"")
641655
}

0 commit comments

Comments
 (0)