trpc.group/trpc-go/trpc-cmdline@v1.0.9/util/semver/semver_test.go (about) 1 // Tencent is pleased to support the open source community by making tRPC available. 2 // 3 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 4 // All rights reserved. 5 // 6 // If you have downloaded a copy of the tRPC source code from Tencent, 7 // please note that tRPC source code is licensed under the Apache 2.0 License, 8 // A copy of the Apache 2.0 License is included in this file. 9 10 package semver 11 12 import "testing" 13 14 func TestNewerThan(t *testing.T) { 15 type args struct { 16 v1 string 17 v2 string 18 } 19 tests := []struct { 20 name string 21 args args 22 want bool 23 }{ 24 {"1.0.0 vs 1.0.0", args{"1.0.0", "1.0.0"}, false}, 25 {"1.0.0 vs 1.0.1", args{"1.0.0", "1.0.1"}, false}, 26 {"1.0.0 vs 1.1.0", args{"1.0.0", "1.1.0"}, false}, 27 {"1.0.0 vs 1.1.1", args{"1.0.0", "1.1.1"}, false}, 28 {"2.0.0 vs 1.0.0", args{"2.0.0", "1.0.0"}, true}, 29 {"2.0.0 vs 1.0.1", args{"2.0.0", "1.0.1"}, true}, 30 {"2.0.0 vs 1.1.0", args{"2.0.0", "1.1.0"}, true}, 31 {"2.0.0 vs 1.1.1", args{"2.0.0", "1.1.1"}, true}, 32 {"2.5.0 vs 2.6.0", args{"2.5.0", "2.6.0"}, false}, 33 {"2.5.0 vs 2.6.1", args{"2.5.0", "2.6.1"}, false}, 34 {"2.5.1 vs 2.5.1", args{"2.5.1", "2.5.1"}, false}, 35 {"2.6.0 vs 2.6.0", args{"2.6.0", "2.6.0"}, false}, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 if got := NewerThan(tt.args.v1, tt.args.v2); got != tt.want { 40 t.Errorf("NewerThan() = %v, want %v", got, tt.want) 41 } 42 }) 43 } 44 } 45 46 func TestVersions(t *testing.T) { 47 tests := []struct { 48 name string 49 ver string 50 wantMajor int 51 wantMinor int 52 wantRevision int 53 }{ 54 {"v1.2.3-dev", "v1.2.3-dev", 1, 2, 3}, 55 {"1.2.3-dev", "1.2.3-dev", 1, 2, 3}, 56 {"1.2.3", "1.2.3", 1, 2, 3}, 57 } 58 for _, tt := range tests { 59 t.Run(tt.name, func(t *testing.T) { 60 gotMajor, gotMinor, gotRevision := Versions(tt.ver) 61 if gotMajor != tt.wantMajor { 62 t.Errorf("Versions() gotMajor = %v, want %v", gotMajor, tt.wantMajor) 63 } 64 if gotMinor != tt.wantMinor { 65 t.Errorf("Versions() gotMinor = %v, want %v", gotMinor, tt.wantMinor) 66 } 67 if gotRevision != tt.wantRevision { 68 t.Errorf("Versions() gotRevision = %v, want %v", gotRevision, tt.wantRevision) 69 } 70 }) 71 } 72 }