github.com/abemedia/appcast@v0.4.0/integrations/sparkle/config_test.go (about) 1 package sparkle_test 2 3 import ( 4 "testing" 5 6 "github.com/abemedia/appcast/integrations/sparkle" 7 "github.com/google/go-cmp/cmp" 8 ) 9 10 func TestConfigGetOptions(t *testing.T) { 11 c := &sparkle.Config{ 12 Settings: []sparkle.Rule{ 13 { 14 OS: sparkle.MacOS, 15 Settings: &sparkle.Settings{ 16 MinimumSystemVersion: "10.13.0", 17 }, 18 }, 19 { 20 OS: sparkle.Windows64, 21 Settings: &sparkle.Settings{ 22 InstallerArguments: "/passive", 23 }, 24 }, 25 { 26 Version: "> 1.0.0", 27 Settings: &sparkle.Settings{ 28 MinimumAutoupdateVersion: "1.0.0", 29 }, 30 }, 31 { 32 Version: ">= 1.1.0, < 1.2.0", 33 Settings: &sparkle.Settings{ 34 CriticalUpdate: true, 35 }, 36 }, 37 { 38 Version: "v1.2.1", 39 Settings: &sparkle.Settings{ 40 CriticalUpdateBelowVersion: "1.1.0", 41 MinimumAutoupdateVersion: "1.1.0", 42 }, 43 }, 44 }, 45 } 46 47 tests := []struct { 48 version string 49 os sparkle.OS 50 want *sparkle.Settings 51 }{ 52 { 53 version: "1.0.0", 54 os: sparkle.Windows64, 55 want: &sparkle.Settings{ 56 InstallerArguments: "/passive", 57 }, 58 }, 59 { 60 version: "1.0.0", 61 os: sparkle.MacOS, 62 want: &sparkle.Settings{ 63 MinimumSystemVersion: "10.13.0", 64 }, 65 }, 66 { 67 version: "1.1.1", 68 os: sparkle.Windows64, 69 want: &sparkle.Settings{ 70 InstallerArguments: "/passive", 71 MinimumAutoupdateVersion: "1.0.0", 72 CriticalUpdate: true, 73 }, 74 }, 75 { 76 version: "1.2.1", 77 os: sparkle.Windows, 78 want: &sparkle.Settings{ 79 MinimumAutoupdateVersion: "1.1.0", 80 CriticalUpdateBelowVersion: "1.1.0", 81 }, 82 }, 83 } 84 85 for _, test := range tests { 86 opt, err := sparkle.GetSettings(c.Settings, test.version, test.os) 87 if err != nil { 88 t.Error(test.version, test.os, err) 89 continue 90 } 91 92 if diff := cmp.Diff(test.want, opt); diff != "" { 93 t.Error(test.version, test.os, diff) 94 } 95 } 96 }