github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/version/parse_test.go (about) 1 package version 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" 9 ) 10 11 func TestParse(t *testing.T) { 12 for _, tt := range []struct { 13 s string 14 v version 15 err bool 16 }{ 17 { 18 s: "1", 19 v: version{Major: 1}, 20 err: false, 21 }, 22 { 23 s: "1.2", 24 v: version{Major: 1, Minor: 2}, 25 err: false, 26 }, 27 { 28 s: "1.2.3", 29 v: version{Major: 1, Minor: 2, Patch: 3}, 30 err: false, 31 }, 32 { 33 s: "1.2.3-alpha", 34 v: version{Major: 1, Minor: 2, Patch: 3, Suffix: "alpha"}, 35 err: false, 36 }, 37 { 38 s: "22.5", 39 v: version{Major: 22, Minor: 5}, 40 err: false, 41 }, 42 { 43 s: "23.1", 44 v: version{Major: 23, Minor: 1}, 45 err: false, 46 }, 47 { 48 s: "23.2", 49 v: version{Major: 23, Minor: 2}, 50 err: false, 51 }, 52 { 53 s: "trunk", 54 v: version{}, 55 err: true, 56 }, 57 } { 58 t.Run(tt.s, func(t *testing.T) { 59 v, err := parse(tt.s) 60 if tt.err { 61 require.Error(t, err) 62 } else { 63 require.NoError(t, err) 64 require.Equal(t, tt.v, v) 65 } 66 }) 67 } 68 } 69 70 var cases = []struct { 71 name string 72 lhs string 73 rhs string 74 lt bool 75 gte bool 76 }{ 77 { 78 name: xtest.CurrentFileLine(), 79 lhs: "1", 80 rhs: "2", 81 lt: true, 82 gte: false, 83 }, 84 { 85 name: xtest.CurrentFileLine(), 86 lhs: "2", 87 rhs: "1", 88 lt: false, 89 gte: true, 90 }, 91 { 92 name: xtest.CurrentFileLine(), 93 lhs: "1", 94 rhs: "1", 95 lt: false, 96 gte: true, 97 }, 98 { 99 name: xtest.CurrentFileLine(), 100 lhs: "22.5", 101 rhs: "23.1", 102 lt: true, 103 gte: false, 104 }, 105 { 106 name: xtest.CurrentFileLine(), 107 lhs: "23.1", 108 rhs: "22.5", 109 lt: false, 110 gte: true, 111 }, 112 { 113 name: xtest.CurrentFileLine(), 114 lhs: "trunk", 115 rhs: "22.5", 116 lt: false, 117 gte: false, 118 }, 119 { 120 name: xtest.CurrentFileLine(), 121 lhs: "trunk", 122 rhs: "23.1", 123 lt: false, 124 gte: false, 125 }, 126 { 127 name: xtest.CurrentFileLine(), 128 lhs: "22.5", 129 rhs: "trunk", 130 lt: false, 131 gte: false, 132 }, 133 { 134 name: xtest.CurrentFileLine(), 135 lhs: "23.1", 136 rhs: "trunk", 137 lt: false, 138 gte: false, 139 }, 140 } 141 142 func TestLt(t *testing.T) { 143 for _, tt := range cases { 144 t.Run(tt.name, func(t *testing.T) { 145 require.Equal(t, tt.lt, Lt(tt.lhs, tt.rhs)) 146 }) 147 } 148 } 149 150 func TestGte(t *testing.T) { 151 for _, tt := range cases { 152 t.Run(tt.name, func(t *testing.T) { 153 require.Equal(t, tt.gte, Gte(tt.lhs, tt.rhs)) 154 }) 155 } 156 }