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

Skip to content

Commit 12e502a

Browse files
committed
Fix: parallel
1 parent 7165276 commit 12e502a

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

coderd/coderdtest/swagger_test.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
type swaggerComment struct {
1919
summary string
2020
id string
21+
tags string
2122

2223
method string
2324
router string
@@ -40,14 +41,19 @@ func TestAllEndpointsDocumented(t *testing.T) {
4041
route = route[:len(route)-1]
4142
}
4243

43-
c := findSwaggerCommentByMethodAndRoute(swaggerComments, method, route)
44-
assert.NotNil(t, c, "Missing @Router annotation for: [%s] %s", method, route)
45-
if c == nil {
46-
return nil // do not fail next assertion for this route
47-
}
44+
t.Run(method+" "+route, func(t *testing.T) {
45+
t.Parallel()
46+
47+
c := findSwaggerCommentByMethodAndRoute(swaggerComments, method, route)
48+
assert.NotNil(t, c, "Missing @Router annotation")
49+
if c == nil {
50+
return // do not fail next assertion for this route
51+
}
4852

49-
assertConsistencyBetweenRouteIDAndSummary(t, *c)
50-
assertSuccessOrFailureDefined(t, *c)
53+
assertConsistencyBetweenRouteIDAndSummary(t, *c)
54+
assertSuccessOrFailureDefined(t, *c)
55+
assertRequiredAnnotations(t, *c)
56+
})
5157
return nil
5258
})
5359
}
@@ -103,6 +109,9 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) swaggerComment {
103109
c.hasSuccess = true
104110
} else if strings.Contains(text, "@Failure ") {
105111
c.hasFailure = true
112+
} else if strings.Contains(text, "@Tags ") {
113+
args := strings.SplitN(text, " ", 3)
114+
c.tags = args[2]
106115
}
107116
}
108117
return c
@@ -130,3 +139,9 @@ func assertConsistencyBetweenRouteIDAndSummary(t *testing.T, comment swaggerComm
130139
func assertSuccessOrFailureDefined(t *testing.T, comment swaggerComment) {
131140
assert.True(t, comment.hasSuccess || comment.hasFailure, "At least one @Success or @Failure annotation must be defined")
132141
}
142+
143+
func assertRequiredAnnotations(t *testing.T, comment swaggerComment) {
144+
assert.NotEmpty(t, comment.id, "@ID must be defined")
145+
assert.NotEmpty(t, comment.summary, "@Summary must be defined")
146+
assert.NotEmpty(t, comment.tags, "@Tags must be defined")
147+
}

0 commit comments

Comments
 (0)