-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recover from bad parsing of golang binary (#1371)
Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
3 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package golang | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"runtime/debug" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getBuildInfo(t *testing.T) { | ||
type args struct { | ||
r io.ReaderAt | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantBi *debug.BuildInfo | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "recover from panic", | ||
args: args{ | ||
r: nil, // trying to use a nil reader will cause a panic | ||
}, | ||
wantBi: nil, // we should not return anything useful | ||
wantErr: assert.Error, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotBi, err := getBuildInfo(tt.args.r) | ||
if !tt.wantErr(t, err, fmt.Sprintf("getBuildInfo(%v)", tt.args.r)) { | ||
return | ||
} | ||
assert.Equalf(t, tt.wantBi, gotBi, "getBuildInfo(%v)", tt.args.r) | ||
}) | ||
} | ||
} |