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