github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/version_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "fmt" 8 "testing" 9 ) 10 11 func TestSplitVersion(t *testing.T) { 12 major1, minor1, patch1 := SplitVersion("junk") 13 if major1 != 0 || minor1 != 0 || patch1 != 0 { 14 t.Fatal() 15 } 16 17 major2, minor2, patch2 := SplitVersion("1.2.3") 18 if major2 != 1 || minor2 != 2 || patch2 != 3 { 19 t.Fatal() 20 } 21 22 major3, minor3, patch3 := SplitVersion("1.2") 23 if major3 != 1 || minor3 != 2 || patch3 != 0 { 24 t.Fatal() 25 } 26 27 major4, minor4, patch4 := SplitVersion("1") 28 if major4 != 1 || minor4 != 0 || patch4 != 0 { 29 t.Fatal() 30 } 31 32 major5, minor5, patch5 := SplitVersion("1.2.3.junkgoeswhere") 33 if major5 != 1 || minor5 != 2 || patch5 != 3 { 34 t.Fatal() 35 } 36 } 37 38 func TestGetPreviousVersion(t *testing.T) { 39 if GetPreviousVersion("1.3.0") != "1.2.0" { 40 t.Fatal() 41 } 42 43 if GetPreviousVersion("1.2.1") != "1.1.0" { 44 t.Fatal() 45 } 46 47 if GetPreviousVersion("1.1.0") != "1.0.0" { 48 t.Fatal() 49 } 50 51 if GetPreviousVersion("1.0.0") != "0.7.0" { 52 t.Fatal() 53 } 54 55 if GetPreviousVersion("0.7.1") != "0.6.0" { 56 t.Fatal() 57 } 58 59 if GetPreviousVersion("0.5.0") != "" { 60 t.Fatal() 61 } 62 } 63 64 func TestIsCurrentVersion(t *testing.T) { 65 major, minor, patch := SplitVersion(CurrentVersion) 66 67 if !IsCurrentVersion(CurrentVersion) { 68 t.Fatal() 69 } 70 71 if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor, patch+100)) { 72 t.Fatal() 73 } 74 75 if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor+1, patch)) { 76 t.Fatal() 77 } 78 79 if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major+1, minor, patch)) { 80 t.Fatal() 81 } 82 } 83 84 func TestIsPreviousVersionsSupported(t *testing.T) { 85 86 if !IsPreviousVersionsSupported(versionsWithoutHotFixes[0]) { 87 t.Fatal() 88 } 89 90 if !IsPreviousVersionsSupported(versionsWithoutHotFixes[1]) { 91 t.Fatal() 92 } 93 94 if !IsPreviousVersionsSupported(versionsWithoutHotFixes[2]) { 95 t.Fatal() 96 } 97 98 if IsPreviousVersionsSupported(versionsWithoutHotFixes[4]) { 99 t.Fatal() 100 } 101 102 if IsPreviousVersionsSupported(versionsWithoutHotFixes[5]) { 103 t.Fatal() 104 } 105 }