| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package task
- import (
- "testing"
- "dsbqj-admin/model/mongo/abver"
- "dsbqj-admin/model/mongo/md5"
- )
- func TestVersionConfigCacheReturnsValueAndTagVersion(t *testing.T) {
- cache := &VersionConfigCache{
- abVers: map[string][]*abver.AbVer{
- "wx": {
- {Platform: "wx", Version: "1.0.2", Value: "old", EnvVersions: []string{"release"}, External: true},
- {Platform: "wx", Version: "1.0.10", Value: "new", EnvVersions: []string{"release"}, External: true},
- {Platform: "wx", Version: "1.0.20", Value: "hidden", External: false},
- {Platform: "wx", Version: "2.0.0", Value: "trial", EnvVersions: []string{"trial"}, External: true},
- },
- },
- md5s: map[string][]*md5.MD5{
- "wx": {
- {Platform: "wx", Version: "1.0.5", Value: "hashes", EnvVersions: []string{"release"}, External: true},
- },
- },
- }
- if got := cache.GetAbVer("wx", "release"); got != (ConfigValue{Version: "1.0.10", Value: "new"}) {
- t.Fatalf("abVer should return its selected tag and value together: %#v", got)
- }
- if got := cache.GetMD5("wx", "release"); got != (ConfigValue{Version: "1.0.5", Value: "hashes"}) {
- t.Fatalf("md5 should return its own tag and value: %#v", got)
- }
- if got := cache.GetAbVer("wx", "trial"); got != (ConfigValue{Version: "2.0.0", Value: "trial"}) {
- t.Fatalf("trial should select its own tag and value: %#v", got)
- }
- if got := cache.GetMD5("wx", "trial"); got != (ConfigValue{}) {
- t.Fatalf("missing config should return empty tag and value: %#v", got)
- }
- }
- func TestVersionConfigCacheLegacyFallbackAndEmptyValue(t *testing.T) {
- cache := &VersionConfigCache{
- abVers: map[string][]*abver.AbVer{
- "": {{Version: "1.0.1", Value: "legacy", External: true}},
- "wx": {{Platform: "wx", Version: "1.0.2", Value: "", External: true}},
- },
- }
- if got := cache.GetAbVer("wx", "release"); got != (ConfigValue{Version: "1.0.2", Value: ""}) {
- t.Fatalf("platform record with empty value must not fall back to legacy tag: %#v", got)
- }
- if got := cache.GetAbVer("dy", "release"); got != (ConfigValue{Version: "1.0.1", Value: "legacy"}) {
- t.Fatalf("missing platform record should use legacy fallback: %#v", got)
- }
- }
- func TestCompareConfigVersionUsesNumericSegments(t *testing.T) {
- if CompareConfigVersion("1.0.10", "1.0.9") <= 0 {
- t.Fatal("1.0.10 should sort before 1.0.9 in descending order")
- }
- if CompareConfigVersion("1.0.4", "1.0.3") <= 0 {
- t.Fatal("1.0.4 should sort before 1.0.3 in descending order")
- }
- }
|