Skip to content

Commit 5d1cc26

Browse files
committed
Move hexDecode test helper into a test file
The inclusion of the test helper outside of a _test.go file results in any downstream consumer of this library, either directly or transitively, having the testing package reachable in their binaries. See the following dependency tree for an example which shows how `testing` ends up being included in `github.com/sigstore/sigstore-go`. ```bash goda tree "reach(github.com/sigstore/sigstore-go/pkg/tlog...:all, testing)" ├ github.com/sigstore/sigstore-go/pkg/tlog ├ github.com/sigstore/rekor/pkg/types/dsse/v0.0.1 └ github.com/in-toto/in-toto-golang/in_toto └ github.com/secure-systems-lab/go-securesystemslib/signerverifier └ github.com/sigstore/rekor/pkg/types/intoto/v0.0.2 └ github.com/in-toto/in-toto-golang/in_toto ~ ``` Since the hexDecode helper was only being consumed in tests it was relocated from signerverifier/utils.go to signerverifier/utils_test.go.
1 parent ebae973 commit 5d1cc26

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

signerverifier/utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/pem"
99
"errors"
1010
"hash"
11-
"testing"
1211

1312
"github.com/secure-systems-lab/go-securesystemslib/cjson"
1413
)
@@ -141,12 +140,3 @@ func hashBeforeSigning(data []byte, h hash.Hash) []byte {
141140
h.Write(data)
142141
return h.Sum(nil)
143142
}
144-
145-
func hexDecode(t *testing.T, data string) []byte {
146-
t.Helper()
147-
b, err := hex.DecodeString(data)
148-
if err != nil {
149-
t.Fatal(err)
150-
}
151-
return b
152-
}

signerverifier/utils_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package signerverifier
22

33
import (
4+
"encoding/hex"
45
"os"
56
"path/filepath"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
910
)
1011

12+
func hexDecode(t *testing.T, data string) []byte {
13+
t.Helper()
14+
b, err := hex.DecodeString(data)
15+
if err != nil {
16+
t.Fatal(err)
17+
}
18+
return b
19+
}
20+
1121
func TestLoadKeyFromSSLibBytes(t *testing.T) {
1222
t.Run("RSA public key", func(t *testing.T) {
1323
contents, err := os.ReadFile(filepath.Join("test-data", "rsa-test-key.pub"))

0 commit comments

Comments
 (0)