Skip to content

Commit 788dfe0

Browse files
committed
test(pnpm/v5): refactor test cases
1 parent e1e15e3 commit 788dfe0

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

module/pnpm/v5/data_test.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
package v5
22

3-
import _ "embed"
4-
5-
//go:embed testdata/1.yaml
6-
var testData1 string
7-
8-
//go:embed testdata/2.yaml
9-
var testData2 string
10-
11-
//go:embed testdata/3.yaml
12-
var testData3 string
13-
14-
//go:embed testdata/4.yaml
15-
var testData4 string
3+
import (
4+
"embed"
5+
_ "embed"
6+
)
167

178
//go:embed testdata/5.yaml
189
var testData5 string
1910

20-
var testDataList = []string{
21-
testData1,
22-
testData2,
23-
testData3,
24-
testData4,
25-
testData5,
26-
}
11+
//go:embed testdata/*
12+
var testFiles embed.FS

module/pnpm/v5/v5_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@ import (
44
"encoding/json"
55
"github.com/murphysecurity/murphysec/utils/must"
66
"github.com/stretchr/testify/assert"
7+
"io"
78
"testing"
89
)
910

10-
func TestParseLockfile(t *testing.T) {
11-
for i, s := range testDataList {
12-
lockfile, e := ParseLockfile([]byte(s))
13-
assert.NoError(t, e, i)
14-
assert.NotNil(t, lockfile, i)
11+
func TestLockfile(t *testing.T) {
12+
files, _ := testFiles.ReadDir("testdata")
13+
assert.NotEmpty(t, files)
14+
for _, s := range files {
15+
t.Run(s.Name(), func(t *testing.T) {
16+
f, e := testFiles.Open("testdata/" + s.Name())
17+
assert.NoError(t, e)
18+
defer func() { assert.NoError(t, f.Close()) }()
19+
data, e := io.ReadAll(f)
20+
assert.NoError(t, e)
21+
lockfile, e := ParseLockfile(data)
22+
assert.NoError(t, e)
23+
assert.NotNil(t, lockfile)
24+
25+
})
1526
}
1627
}
1728

1829
func TestBuildDepTree(t *testing.T) {
19-
l, _ := ParseLockfile([]byte(testDataList[4]))
30+
31+
l, _ := ParseLockfile([]byte(testData5))
2032
tree := BuildDepTree(l, nil, "")
2133
assert.NotNil(t, tree)
2234
t.Log(string(must.A(json.MarshalIndent(tree, "| ", " "))))

0 commit comments

Comments
 (0)