-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read module dependencies from debug.BuildInfo instead of go.mod #199
Changes from all commits
ef35bee
20f9359
b86dee2
3b8b7dd
10135ac
a7740e4
72e3d05
a168844
baaaf74
9aedba0
b3548d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ package sentry | |
import ( | ||
"path/filepath" | ||
"regexp" | ||
"runtime/debug" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestTransformStringsIntoRegexps(t *testing.T) { | ||
|
@@ -238,3 +241,104 @@ func TestContextifyFramesNonexistingFilesShouldNotDropFrames(t *testing.T) { | |
contextifiedFrames := cfi.contextify(frames) | ||
assertEqual(t, len(contextifiedFrames), len(frames)) | ||
} | ||
|
||
func TestExtractModules(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
info *debug.BuildInfo | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "no require modules", | ||
info: &debug.BuildInfo{ | ||
Main: debug.Module{ | ||
Path: "my/module", | ||
Version: "(devel)", | ||
}, | ||
Deps: []*debug.Module{}, | ||
}, | ||
want: map[string]string{ | ||
"my/module": "(devel)", | ||
}, | ||
}, | ||
{ | ||
name: "have require modules", | ||
info: &debug.BuildInfo{ | ||
Main: debug.Module{ | ||
Path: "my/module", | ||
Version: "(devel)", | ||
}, | ||
Deps: []*debug.Module{ | ||
{ | ||
Path: "github.com/getsentry/sentry-go", | ||
Version: "v0.5.1", | ||
}, | ||
{ | ||
Path: "github.com/gin-gonic/gin", | ||
Version: "v1.4.0", | ||
}, | ||
}, | ||
}, | ||
want: map[string]string{ | ||
"my/module": "(devel)", | ||
"github.com/getsentry/sentry-go": "v0.5.1", | ||
"github.com/gin-gonic/gin": "v1.4.0", | ||
}, | ||
}, | ||
{ | ||
name: "replace module with local module", | ||
info: &debug.BuildInfo{ | ||
Main: debug.Module{ | ||
Path: "my/module", | ||
Version: "(devel)", | ||
}, | ||
Deps: []*debug.Module{ | ||
{ | ||
Path: "github.com/getsentry/sentry-go", | ||
Version: "v0.5.1", | ||
Replace: &debug.Module{ | ||
Path: "pkg/sentry", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[string]string{ | ||
"my/module": "(devel)", | ||
"github.com/getsentry/sentry-go": "v0.5.1 => pkg/sentry", | ||
}, | ||
}, | ||
{ | ||
name: "replace module with another remote module", | ||
info: &debug.BuildInfo{ | ||
Main: debug.Module{ | ||
Path: "my/module", | ||
Version: "(devel)", | ||
}, | ||
Deps: []*debug.Module{ | ||
{ | ||
Path: "github.com/ugorji/go", | ||
Version: "v1.1.4", | ||
Replace: &debug.Module{ | ||
Path: "github.com/ugorji/go/codec", | ||
Version: "v0.0.0-20190204201341-e444a5086c43", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[string]string{ | ||
"my/module": "(devel)", | ||
"github.com/ugorji/go": "v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := extractModules(tt.info) | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Errorf("modules info mismatch (-want +got):\n%s", diff) | ||
} | ||
Comment on lines
+339
to
+341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took the liberty to change this to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rhcarvalho I think we can turn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point, as it just limits the usability. Personally I prefer calling
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Thanks for your point. |
||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that at the moment the
Version
of the main module (in fact, the module that contains packagemain
) is always"(devel)"
. That is unfortunate, but at least the module name will be in Sentry. Proper version can be added using the Releases feature.golang/go#29228