diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-05-04 18:48:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 18:48:23 +0800 |
commit | 9fd4f5562d7a59abbef5e78d44fb85a0041e0733 (patch) | |
tree | 8b917bfbf8d2c7fb186e832f52f29b5942d43b12 /internal/semverutil/semverutil_test.go | |
parent | 9bb218734c53c98a13264c2f4f479e3633ccfe18 (diff) |
all: use semver to compare versions (#6147)
Diffstat (limited to 'internal/semverutil/semverutil_test.go')
-rw-r--r-- | internal/semverutil/semverutil_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/semverutil/semverutil_test.go b/internal/semverutil/semverutil_test.go new file mode 100644 index 00000000..d11421b8 --- /dev/null +++ b/internal/semverutil/semverutil_test.go @@ -0,0 +1,32 @@ +// Copyright 2020 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package semverutil + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCheck(t *testing.T) { + tests := []struct { + version1 string + comparison string + version2 string + expVal bool + }{ + {version1: "1.0.c", comparison: ">", version2: "0.9", expVal: false}, + {version1: "1.0.1", comparison: ">", version2: "0.9.a", expVal: false}, + + {version1: "7.2", comparison: ">=", version2: "5.1", expVal: true}, + {version1: "1.8.3.1", comparison: ">=", version2: "1.8.3", expVal: true}, + {version1: "0.12.0+dev", comparison: ">=", version2: "0.11.68.1023", expVal: true}, + } + for _, test := range tests { + t.Run(test.version1+" "+test.comparison+" "+test.version2, func(t *testing.T) { + assert.Equal(t, test.expVal, Compare(test.version1, test.comparison, test.version2)) + }) + } +} |