version_config_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package task
  2. import (
  3. "testing"
  4. "dsbqj-admin/model/mongo/abver"
  5. "dsbqj-admin/model/mongo/md5"
  6. )
  7. func TestVersionConfigCacheReturnsValueAndTagVersion(t *testing.T) {
  8. cache := &VersionConfigCache{
  9. abVers: map[string][]*abver.AbVer{
  10. "wx": {
  11. {Platform: "wx", Version: "1.0.2", Value: "old", EnvVersions: []string{"release"}, External: true},
  12. {Platform: "wx", Version: "1.0.10", Value: "new", EnvVersions: []string{"release"}, External: true},
  13. {Platform: "wx", Version: "1.0.20", Value: "hidden", External: false},
  14. {Platform: "wx", Version: "2.0.0", Value: "trial", EnvVersions: []string{"trial"}, External: true},
  15. },
  16. },
  17. md5s: map[string][]*md5.MD5{
  18. "wx": {
  19. {Platform: "wx", Version: "1.0.5", Value: "hashes", EnvVersions: []string{"release"}, External: true},
  20. },
  21. },
  22. }
  23. if got := cache.GetAbVer("wx", "release"); got != (ConfigValue{Version: "1.0.10", Value: "new"}) {
  24. t.Fatalf("abVer should return its selected tag and value together: %#v", got)
  25. }
  26. if got := cache.GetMD5("wx", "release"); got != (ConfigValue{Version: "1.0.5", Value: "hashes"}) {
  27. t.Fatalf("md5 should return its own tag and value: %#v", got)
  28. }
  29. if got := cache.GetAbVer("wx", "trial"); got != (ConfigValue{Version: "2.0.0", Value: "trial"}) {
  30. t.Fatalf("trial should select its own tag and value: %#v", got)
  31. }
  32. if got := cache.GetMD5("wx", "trial"); got != (ConfigValue{}) {
  33. t.Fatalf("missing config should return empty tag and value: %#v", got)
  34. }
  35. }
  36. func TestVersionConfigCacheLegacyFallbackAndEmptyValue(t *testing.T) {
  37. cache := &VersionConfigCache{
  38. abVers: map[string][]*abver.AbVer{
  39. "": {{Version: "1.0.1", Value: "legacy", External: true}},
  40. "wx": {{Platform: "wx", Version: "1.0.2", Value: "", External: true}},
  41. },
  42. }
  43. if got := cache.GetAbVer("wx", "release"); got != (ConfigValue{Version: "1.0.2", Value: ""}) {
  44. t.Fatalf("platform record with empty value must not fall back to legacy tag: %#v", got)
  45. }
  46. if got := cache.GetAbVer("dy", "release"); got != (ConfigValue{Version: "1.0.1", Value: "legacy"}) {
  47. t.Fatalf("missing platform record should use legacy fallback: %#v", got)
  48. }
  49. }
  50. func TestCompareConfigVersionUsesNumericSegments(t *testing.T) {
  51. if CompareConfigVersion("1.0.10", "1.0.9") <= 0 {
  52. t.Fatal("1.0.10 should sort before 1.0.9 in descending order")
  53. }
  54. if CompareConfigVersion("1.0.4", "1.0.3") <= 0 {
  55. t.Fatal("1.0.4 should sort before 1.0.3 in descending order")
  56. }
  57. }