Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7165276

Browse files
committed
Assert: success or failure defined
1 parent 76701b8 commit 7165276

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

coderd/coderdtest/swagger_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type swaggerComment struct {
2121

2222
method string
2323
router string
24+
25+
hasSuccess bool
26+
hasFailure bool
2427
}
2528

2629
func TestAllEndpointsDocumented(t *testing.T) {
@@ -44,6 +47,7 @@ func TestAllEndpointsDocumented(t *testing.T) {
4447
}
4548

4649
assertConsistencyBetweenRouteIDAndSummary(t, *c)
50+
assertSuccessOrFailureDefined(t, *c)
4751
return nil
4852
})
4953
}
@@ -95,6 +99,10 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) swaggerComment {
9599
} else if strings.Contains(text, "@ID ") {
96100
args := strings.SplitN(text, " ", 3)
97101
c.id = args[2]
102+
} else if strings.Contains(text, "@Success ") {
103+
c.hasSuccess = true
104+
} else if strings.Contains(text, "@Failure ") {
105+
c.hasFailure = true
98106
}
99107
}
100108
return c
@@ -118,3 +126,7 @@ func assertConsistencyBetweenRouteIDAndSummary(t *testing.T, comment swaggerComm
118126

119127
assert.Equal(t, exp, comment.id, "Router ID must match summary")
120128
}
129+
130+
func assertSuccessOrFailureDefined(t *testing.T, comment swaggerComment) {
131+
assert.True(t, comment.hasSuccess || comment.hasFailure, "At least one @Success or @Failure annotation must be defined")
132+
}

0 commit comments

Comments
 (0)