-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_deps_test.go
44 lines (34 loc) · 1.12 KB
/
module_deps_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package depbump
import (
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/yyle88/neatjson/neatjsons"
"github.com/yyle88/osexistpath/osmustexist"
"github.com/yyle88/runpath"
"github.com/yyle88/syntaxgo/syntaxgo_reflect"
"golang.org/x/mod/modfile"
)
func TestGetModInfo(t *testing.T) {
modInfo, err := GetModInfo(runpath.PARENT.Path())
require.NoError(t, err)
t.Log(neatjsons.S(modInfo))
require.Equal(t, syntaxgo_reflect.GetPkgPathV2[Module](), modInfo.Module.Path)
}
func TestParseModuleFileDemo(t *testing.T) {
const fileName = "go.mod"
modPath := osmustexist.FILE(runpath.PARENT.Join(fileName))
t.Log(modPath)
modData, err := os.ReadFile(modPath)
require.NoError(t, err)
modFile, err := modfile.Parse(fileName, modData, nil)
require.NoError(t, err)
t.Log(neatjsons.S(modFile))
require.Equal(t, syntaxgo_reflect.GetPkgPathV2[Module](), modFile.Module.Mod.Path)
}
func TestParseModuleFile(t *testing.T) {
modFile, err := ParseModuleFile(runpath.PARENT.Path())
require.NoError(t, err)
t.Log(neatjsons.S(modFile))
require.Equal(t, syntaxgo_reflect.GetPkgPathV2[Module](), modFile.Module.Mod.Path)
}