Skip to content

Commit 420a96a

Browse files
committed
Add function without comment in mock and test and add description for it
1 parent 2fd5512 commit 420a96a

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

test-crawler/collector/collector.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,10 @@ func GenerateMethodName(funcName string) string {
145145
return fmt.Sprintf("%s_%s", strings.ToUpper(buf.String()), usecase)
146146
}
147147

148-
// GenerateMethodDescription generates description based on inputParams, returnParams
148+
// GenerateMethodDescription generates description based on comment.
149149
func GenerateMethodDescription(f FunctionAnnotation) string {
150150
if f.Description == "" {
151-
dsc := "Function description not set."
152-
if (f.InputParams != "" && f.InputParams != "()") && f.ReturnValues != "" {
153-
dsc = fmt.Sprintf(`Given a %s, returns %s`, f.InputParams, f.ReturnValues)
154-
} else if (f.InputParams == "" || f.InputParams == "()") && f.ReturnValues != "" {
155-
dsc = fmt.Sprintf(`Returns %s`, f.ReturnValues)
156-
}
157-
return dsc
158-
} else {
159-
return f.Description
151+
return "Function description not set."
160152
}
161-
162-
return "Function description not set."
153+
return f.Description
163154
}

test-crawler/crawler_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestCrawlSingleFileForFunctions(t *testing.T) {
1717
t.Errorf("got error: %v", err.Error())
1818
}
1919

20-
if len(fnsAnn) != 4 {
20+
if len(fnsAnn) != 5 {
2121
t.Errorf("got %q, expected %q methods", len(fnsAnn), 2)
2222
}
2323

@@ -38,9 +38,13 @@ func TestCrawlSingleFileForFunctions(t *testing.T) {
3838

3939
assert.Equal(t, "// FunctionWithPointerReturnValue returns a simple pointer value.", fnsAnn[3].Description)
4040
assert.Equal(t, "FUNCTION_WITH_POINTER_RETURN_VALUE_001", fnsAnn[3].Name)
41-
4241
assert.Equal(t, "()", fnsAnn[3].InputParams)
4342
assert.Equal(t, "*Event", fnsAnn[3].ReturnValues)
43+
44+
assert.Equal(t, "Function description not set.", fnsAnn[4].Description)
45+
assert.Equal(t, "FUNCTION_WITHOUT_COMMENT_001", fnsAnn[4].Name)
46+
assert.Equal(t, "()", fnsAnn[4].InputParams)
47+
assert.Equal(t, "*Event", fnsAnn[4].ReturnValues)
4448
}
4549

4650
func TestMakeYAML(t *testing.T) {

test-crawler/mocks/event.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ func (e *Event) FunctionWithoutParameters() {
3939
func (e *Event) FunctionWithPointerReturnValue() *Event {
4040
return &Event{}
4141
}
42+
43+
func (e *Event) FunctionWithoutComment() *Event {
44+
return &Event{}
45+
}

0 commit comments

Comments
 (0)