cosmossdk.io/client/v2@v2.0.0-beta.1/internal/util/util_test.go (about) 1 package util 2 3 import ( 4 "runtime/debug" 5 "testing" 6 ) 7 8 func TestIsSupportedVersion(t *testing.T) { 9 mockBuildInfo := &debug.BuildInfo{ 10 Deps: []*debug.Module{ 11 { 12 Path: "github.com/cosmos/cosmos-sdk", 13 Version: "v0.50.0", 14 }, 15 { 16 Path: "cosmossdk.io/feegrant", 17 Version: "v0.1.0", 18 }, 19 }, 20 } 21 22 cases := []struct { 23 input string 24 expected bool 25 }{ 26 { 27 input: "", 28 expected: true, 29 }, 30 { 31 input: "not a since comment", 32 expected: true, 33 }, 34 { 35 input: "// Since: cosmos-sdk v0.47", 36 expected: true, 37 }, 38 { 39 input: "// since: Cosmos-SDK 0.50", 40 expected: true, 41 }, 42 { 43 input: "// Since: cosmos-sdk v0.51", 44 expected: false, 45 }, 46 { 47 input: "// Since: cosmos-sdk v1.0.0", 48 expected: false, 49 }, 50 { 51 input: "// since: x/feegrant v0.1.0", 52 expected: true, 53 }, 54 { 55 input: "// since: feegrant v0.0.1", 56 expected: true, 57 }, 58 { 59 input: "// since: feegrant v0.1.0", 60 expected: true, 61 }, 62 { 63 input: "// since: feegrant v0.1", 64 expected: true, 65 }, 66 { 67 input: "// since: feegrant v0.1.1", 68 expected: false, 69 }, 70 { 71 input: "// since: feegrant v0.2.0", 72 expected: false, 73 }, 74 } 75 76 for _, tc := range cases { 77 resp := isSupportedVersion(tc.input, mockBuildInfo) 78 if resp != tc.expected { 79 t.Errorf("expected %v, got %v", tc.expected, resp) 80 } 81 82 resp = isSupportedVersion(tc.input, &debug.BuildInfo{}) 83 if !resp { 84 t.Errorf("expected %v, got %v", true, resp) 85 } 86 } 87 } 88 89 func TestParseSinceComment(t *testing.T) { 90 cases := []struct { 91 input string 92 expectedModuleName string 93 expectedVersion string 94 }{ 95 { 96 input: "", 97 expectedModuleName: "", 98 expectedVersion: "", 99 }, 100 { 101 input: "not a since comment", 102 expectedModuleName: "", 103 expectedVersion: "", 104 }, 105 { 106 input: "// Since: Cosmos SDK 0.50", 107 expectedModuleName: "cosmos-sdk", 108 expectedVersion: "v0.50", 109 }, 110 { 111 input: "// since: Cosmos SDK 0.50", 112 expectedModuleName: "cosmos-sdk", 113 expectedVersion: "v0.50", 114 }, 115 { 116 input: "// since: cosmos sdk 0.50", 117 expectedModuleName: "cosmos-sdk", 118 expectedVersion: "v0.50", 119 }, 120 { 121 input: "// since: Cosmos-SDK 0.50", 122 expectedModuleName: "cosmos-sdk", 123 expectedVersion: "v0.50", 124 }, 125 { 126 input: "// Since: cosmos-sdk v0.50", 127 expectedModuleName: "cosmos-sdk", 128 expectedVersion: "v0.50", 129 }, 130 { 131 input: "//since: cosmos-sdk v0.50.1", 132 expectedModuleName: "cosmos-sdk", 133 expectedVersion: "v0.50.1", 134 }, 135 { 136 input: "// since: cosmos-sdk 0.47.0-veronica", 137 expectedModuleName: "cosmos-sdk", 138 expectedVersion: "v0.47.0-veronica", 139 }, 140 { 141 input: "// Since: x/feegrant v0.1.0", 142 expectedModuleName: "x/feegrant", 143 expectedVersion: "v0.1.0", 144 }, 145 { 146 input: "// since: x/feegrant 0.1", 147 expectedModuleName: "x/feegrant", 148 expectedVersion: "v0.1", 149 }, 150 } 151 152 for _, tc := range cases { 153 moduleName, version := parseSinceComment(tc.input) 154 if moduleName != tc.expectedModuleName { 155 t.Errorf("expected module name %s, got %s", tc.expectedModuleName, moduleName) 156 } 157 if version != tc.expectedVersion { 158 t.Errorf("expected version %s, got %s", tc.expectedVersion, version) 159 } 160 } 161 }