Skip to content

Commit

Permalink
Fix enhance param error when there are multiple params (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePrometheus authored Jan 21, 2024
1 parent 5510aef commit 322daeb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Release Notes.
* Fix ParseVendorModule error for special case in vendor/modules.txt.
* Fix enhance method error when unknown parameter type.
* Fix wrong tracing context when trace have been sampled.
* Fix enhance param error when there are multiple params.

#### Issues and PR
- All issues are [here](https://github.com/apache/skywalking/milestone/197?closed=1)
Expand Down
1 change: 0 additions & 1 deletion tools/go-agent/tools/enhancement.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func EnhanceParameterNames(fields *dst.FieldList, fieldType FieldListType) []*Pa

for _, n := range f.Names {
result = append(result, newParameterInfo(n.Name, f.Type))
break
}
}
}
Expand Down
55 changes: 49 additions & 6 deletions tools/go-agent/tools/enhancement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ func buildParameterValidateInfo(name, typeName string) *ParameterInfo {
}
}

type TestEnhanceParameterInfo struct {
funcCode string
recvs []*ParameterInfo
params []*ParameterInfo
results []*ParameterInfo
}

func TestEnhanceParameterNames(t *testing.T) {
tests := []struct {
funcCode string
recvs []*ParameterInfo
params []*ParameterInfo
results []*ParameterInfo
}{
tests := []TestEnhanceParameterInfo{
{
funcCode: `func (*Example) Test(int) bool {
return false
Expand Down Expand Up @@ -67,6 +69,47 @@ func TestEnhanceParameterNames(t *testing.T) {
},
}

validateParameterTestList(t, tests)
}

func TestEnhanceParameterNamesMultiParams(t *testing.T) {
tests := []TestEnhanceParameterInfo{
{
funcCode: `func (*Example) Test(n, m int) bool {
return false
}`,
recvs: []*ParameterInfo{
buildParameterValidateInfo("skywalking_recv_0", "*Example"),
},
params: []*ParameterInfo{
buildParameterValidateInfo("n", "int"),
buildParameterValidateInfo("m", "int"),
},
results: []*ParameterInfo{
buildParameterValidateInfo("skywalking_result_0", "bool"),
},
},
{
funcCode: `func (e *Example) Test(n, m int) (b bool) {
return false
}`,
recvs: []*ParameterInfo{
buildParameterValidateInfo("e", "*Example"),
},
params: []*ParameterInfo{
buildParameterValidateInfo("n", "int"),
buildParameterValidateInfo("m", "int"),
},
results: []*ParameterInfo{
buildParameterValidateInfo("b", "bool"),
},
},
}

validateParameterTestList(t, tests)
}

func validateParameterTestList(t *testing.T, tests []TestEnhanceParameterInfo) {
for i, test := range tests {
fun := GoStringToDecls(test.funcCode)[0].(*dst.FuncDecl)
var actualRecv, actualParams, actualResults []*ParameterInfo
Expand Down

0 comments on commit 322daeb

Please sign in to comment.