-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(version): update version command to return v2 info #22807
Changes from 12 commits
f94d30d
5924a8a
2b04cd8
39726ac
114e108
7fe6a11
417fbea
98f5bc3
e1b5c70
0f58363
b3d6e97
8b88721
e13146d
c6d186b
c125642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,14 +143,17 @@ message GetNodeInfoResponse { | |
|
||
// VersionInfo is the type for the GetNodeInfoResponse message. | ||
message VersionInfo { | ||
string name = 1; | ||
string app_name = 2; | ||
string version = 3; | ||
string git_commit = 4; | ||
string build_tags = 5; | ||
string go_version = 6; | ||
repeated Module build_deps = 7; | ||
string cosmos_sdk_version = 8 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.43"]; | ||
string name = 1; | ||
string app_name = 2; | ||
string version = 3; | ||
string git_commit = 4; | ||
string build_tags = 5; | ||
string go_version = 6; | ||
repeated Module build_deps = 7; | ||
string cosmos_sdk_version = 8 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.43"]; | ||
string comet_server_version = 9 [(cosmos_proto.field_added_in) = "cosmos-sdk 2.0"]; | ||
string runtime_version = 10 [(cosmos_proto.field_added_in) = "cosmos-sdk 2.0"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the proper version to be adding as an annotation here? not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be |
||
string stf_version = 11 [(cosmos_proto.field_added_in) = "cosmos-sdk 2.0"]; | ||
} | ||
|
||
// Module is the type for VersionInfo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) { | ||
var 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)) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,11 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
"github.com/cosmos/cosmos-sdk/testutil/cmdtest" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
"github.com/stretchr/testify/require" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you run |
||
) | ||
|
||
func TestNewInfo(t *testing.T) { | ||
|
@@ -86,11 +85,12 @@ func TestCLI(t *testing.T) { | |
info.GoVersion = "" | ||
|
||
want := version.Info{ | ||
Name: testName, | ||
AppName: testAppName, | ||
Version: testVersion, | ||
GitCommit: testCommit, | ||
BuildTags: testBuildTags, | ||
Name: testName, | ||
AppName: testAppName, | ||
Version: testVersion, | ||
GitCommit: testCommit, | ||
BuildTags: testBuildTags, | ||
CosmosSdkVersion: "unable to read deps", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhance test coverage for v2 version information The current test case doesn't adequately cover the new version information features described in the PR objectives:
Consider adding these test cases: func TestCLI(t *testing.T) {
+ tests := []struct {
+ name string
+ buildOpts string
+ wantVersion version.Info
+ }{
+ {
+ name: "with v2 build options",
+ buildOpts: "v2",
+ wantVersion: version.Info{
+ Name: testName,
+ AppName: testAppName,
+ Version: testVersion,
+ GitCommit: testCommit,
+ BuildTags: testBuildTags,
+ RuntimeVersion: "v2.0.0", // Expected v2 runtime version
+ StfVersion: "v1.0.0", // Expected STF version
+ CometServerVersion: "v0.1.0", // Expected server version
+ },
+ },
+ {
+ name: "without v2 build options",
+ buildOpts: "",
+ wantVersion: version.Info{
+ Name: testName,
+ AppName: testAppName,
+ Version: testVersion,
+ GitCommit: testCommit,
+ BuildTags: testBuildTags,
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ origBuildOpts := os.Getenv("COSMOS_BUILD_OPTIONS")
+ t.Cleanup(func() {
+ os.Setenv("COSMOS_BUILD_OPTIONS", origBuildOpts)
+ })
+ os.Setenv("COSMOS_BUILD_OPTIONS", tt.buildOpts)
+
+ // Your existing test logic here, but compare against tt.wantVersion
+ })
+ }
}
|
||
} | ||
require.Equal(t, want, info) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
(version)