Skip to content

Commit

Permalink
test for traceidstring
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm committed Oct 4, 2024
1 parent db7ef15 commit 9dc8b18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/v2check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
&v2check.V1ImportURL{},
&v2check.DDTraceTypes{},
&v2check.TracerStructs{},
// TODO: &v2check.TraceIDString{},
&v2check.TraceIDString{},
&v2check.WithServiceName{},
)
c.Run(singlechecker.Main)
Expand Down
23 changes: 21 additions & 2 deletions tools/v2check/v2check/known_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,30 @@ type TraceIDString struct {
}

func (c TraceIDString) Fixes() []analysis.SuggestedFix {
return []analysis.SuggestedFix{}
fn, ok := c.ctx.Value("fn").(func())
if !ok || fn == nil {
return nil
}

return []analysis.SuggestedFix{
{
Message: "use TraceIDLower()",
TextEdits: []analysis.TextEdit{
{
Pos: c.Pos(),
End: c.End(),
NewText: []byte("TraceIDLower()"),
},
},
},
}
}

func (c TraceIDString) Probes() []Probe {
return []Probe{}
return []Probe{
IsFuncCall,
WithFunctionName("TraceID"),
}
}

func (c TraceIDString) String() string {
Expand Down
5 changes: 5 additions & 0 deletions tools/v2check/v2check/v2check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func TestWithServiceName(t *testing.T) {
c.Run(testRunner(t, "withservicename"))
}

func TestTraceIDString(t *testing.T) {
c := v2check.NewChecker(&v2check.TraceIDString{})
c.Run(testRunner(t, "traceidstring"))
}

func TestTracerStructs(t *testing.T) {
c := v2check.NewChecker(&v2check.TracerStructs{})
c.Run(testRunner(t, "tracerstructs"))
Expand Down

0 comments on commit 9dc8b18

Please sign in to comment.