forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_test.go
166 lines (160 loc) · 3.08 KB
/
build_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package version
import (
"runtime/debug"
"testing"
"github.com/stretchr/testify/require"
)
func Test_getSDKBuildInfo(t *testing.T) {
tests := []struct {
name string
debugBuildInfo *debug.BuildInfo
want sdkBuildInfo
}{
{
name: "no deps",
debugBuildInfo: &debug.BuildInfo{
Deps: nil,
},
want: sdkBuildInfo{},
},
{
name: "cosmos-sdk dep only",
debugBuildInfo: &debug.BuildInfo{
Deps: []*debug.Module{
{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
},
},
},
want: sdkBuildInfo{
sdkVersion: "v2.0.0",
},
},
{
name: "all depo",
debugBuildInfo: &debug.BuildInfo{
Deps: []*debug.Module{
{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
},
{
Path: "cosmossdk.io/server/v2/cometbft",
Version: "v2.0.1",
},
{
Path: "cosmossdk.io/runtime/v2",
Version: "v2.0.2",
},
{
Path: "cosmossdk.io/server/v2/stf",
Version: "v2.0.3",
},
},
},
want: sdkBuildInfo{
sdkVersion: "v2.0.0",
cometServerVersion: "v2.0.1",
runtimeVersion: "v2.0.2",
stfVersion: "v2.0.3",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, getSDKBuildInfo(tt.debugBuildInfo))
})
}
}
func Test_extractVersionFromBuildInfo(t *testing.T) {
tests := []struct {
name string
dep *debug.Module
want string
}{
{
name: "no replace",
dep: &debug.Module{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
},
want: "v2.0.0",
},
{
name: "devel replace ",
dep: &debug.Module{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
Replace: &debug.Module{
Version: "(devel)",
},
},
want: "v2.0.0",
},
{
name: "non-devel replace ",
dep: &debug.Module{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
Replace: &debug.Module{
Version: "v1.0.3",
},
},
want: "v1.0.3",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, extractVersionFromBuildInfo(tt.dep))
})
}
}
func Test_depsFromBuildInfo(t *testing.T) {
modules := []*debug.Module{
{
Path: "github.com/cosmos/cosmos-sdk",
Version: "v2.0.0",
},
{
Path: "cosmossdk.io/server/v2/cometbft",
Version: "v2.0.1",
},
{
Path: "cosmossdk.io/runtime/v2",
Version: "v2.0.2",
},
{
Path: "cosmossdk.io/server/v2/stf",
Version: "v2.0.3",
},
}
tests := []struct {
name string
debugBuildInfo *debug.BuildInfo
want []buildDep
}{
{
name: "no deps",
debugBuildInfo: &debug.BuildInfo{},
want: nil,
},
{
name: "deps",
debugBuildInfo: &debug.BuildInfo{
Deps: modules,
},
want: []buildDep{
{modules[0]},
{modules[1]},
{modules[2]},
{modules[3]},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, depsFromBuildInfo(tt.debugBuildInfo))
})
}
}