Skip to content

Commit d561ef0

Browse files
committed
fix: unit tests
1 parent 957be74 commit d561ef0

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

file_test.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -423,22 +423,10 @@ func TestTypeString(t *testing.T) {
423423
}
424424
}
425425

426-
func TestNewFatFile(t *testing.T) {
427-
428-
f, err := os.Open("/usr/lib/libLeaksAtExit.dylib")
429-
if err != nil {
430-
t.Fatal(err)
431-
}
432-
433-
fat, err := NewFatFile(f)
434-
if err != nil {
435-
t.Fatal(err)
436-
}
437-
438-
fmt.Println(fat.Arches[0].FileTOC.String())
439-
440-
if fat.Arches[0].UUID().UUID.String() != "273FB269-0D2F-3A78-9874-09E004F8B069" {
441-
t.Errorf("macho.UUID() = %s; want test", fat.Arches[0].UUID())
426+
func TestOpenBadDysymCmd(t *testing.T) {
427+
_, err := openObscured("internal/testdata/gcc-amd64-darwin-exec-with-bad-dysym.base64")
428+
if err == nil {
429+
t.Fatal("openObscured did not fail when opening a file with an invalid dynamic symbol table command")
442430
}
443431
}
444432

@@ -644,7 +632,7 @@ func TestNewFile(t *testing.T) {
644632
if t1, ok := typ.(*dwarf.StructType); ok {
645633
if strings.EqualFold(t1.StructName, "thread") {
646634
if !t1.Incomplete {
647-
fmt.Println(t1.Defn())
635+
fmt.Println(t1.Defn(false))
648636
}
649637
}
650638
}

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/blacktop/go-dwarf v1.0.9 h1:eT/L7gt0gllvvgnRXY0MFKjNB6+jtOY5DTm2ynVX2dY=
2-
github.com/blacktop/go-dwarf v1.0.9/go.mod h1:4W2FKgSFYcZLDwnR7k+apv5i3nrau4NGl9N6VQ9DSTo=
1+
github.com/blacktop/go-dwarf v1.0.10 h1:i9zYgcIROETsNZ6V+zZn3uDH21FCG5BLLZ837GitxS0=
2+
github.com/blacktop/go-dwarf v1.0.10/go.mod h1:4W2FKgSFYcZLDwnR7k+apv5i3nrau4NGl9N6VQ9DSTo=

internal/obscuretestdata/obscuretestdata.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ package obscuretestdata
1010
import (
1111
"encoding/base64"
1212
"io"
13-
"io/ioutil"
1413
"os"
1514
)
1615

16+
// Rot13 returns the rot13 encoding or decoding of its input.
17+
func Rot13(data []byte) []byte {
18+
out := make([]byte, len(data))
19+
copy(out, data)
20+
for i, c := range out {
21+
switch {
22+
case 'A' <= c && c <= 'M' || 'a' <= c && c <= 'm':
23+
out[i] = c + 13
24+
case 'N' <= c && c <= 'Z' || 'n' <= c && c <= 'z':
25+
out[i] = c - 13
26+
}
27+
}
28+
return out
29+
}
30+
1731
// DecodeToTempFile decodes the named file to a temporary location.
1832
// If successful, it returns the path of the decoded file.
1933
// The caller is responsible for ensuring that the temporary file is removed.
@@ -24,7 +38,7 @@ func DecodeToTempFile(name string) (path string, err error) {
2438
}
2539
defer f.Close()
2640

27-
tmp, err := ioutil.TempFile("", "obscuretestdata-decoded-")
41+
tmp, err := os.CreateTemp("", "obscuretestdata-decoded-")
2842
if err != nil {
2943
return "", err
3044
}
@@ -47,5 +61,5 @@ func ReadFile(name string) ([]byte, error) {
4761
return nil, err
4862
}
4963
defer f.Close()
50-
return ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
64+
return io.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
5165
}

0 commit comments

Comments
 (0)