| 1 | package winuninstall |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestPlanDoesNotPromoteLegacyOnlyRegistrationWithoutManagedWailsInstall(t *testing.T) { |
| 6 | legacy := &Registration{ |
| 7 | DisplayName: "Reasonix", |
| 8 | DisplayVersion: "0.53.0", |
| 9 | InstallLocation: `"D:\Reasonix"`, |
| 10 | UninstallString: `"D:\Reasonix\uninstall.exe"`, |
| 11 | } |
| 12 | |
| 13 | got, err := Plan(nil, legacy, `D:\Reasonix`, "v1.21.0", true) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if got.Managed || got.DeleteLegacy { |
| 18 | t.Fatalf("plan = %+v, want the full installer to migrate a legacy-only registration", got) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func TestPlanRefreshesManagedWailsRegistrationAndDeletesMatchingLegacyAlias(t *testing.T) { |
| 23 | current := &Registration{ |
| 24 | DisplayName: "Reasonix", |
| 25 | DisplayVersion: "1.18.0", |
| 26 | InstallLocation: `D:\Reasonix`, |
| 27 | UninstallString: `"D:\Reasonix\uninstall.exe"`, |
| 28 | } |
| 29 | legacy := &Registration{ |
| 30 | DisplayName: "Reasonix", |
| 31 | DisplayVersion: "0.53.0", |
| 32 | InstallLocation: `D:\Reasonix`, |
| 33 | UninstallString: `"D:\Reasonix\uninstall.exe"`, |
| 34 | } |
| 35 | |
| 36 | got, err := Plan(current, legacy, `d:\reasonix\`, "1.21.0", true) |
| 37 | if err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | if !got.Managed || !got.DeleteLegacy || got.Desired.DisplayVersion != "1.21.0" { |
| 41 | t.Fatalf("plan = %+v, want current registration refresh", got) |
| 42 | } |
| 43 | if got.Desired.InstallLocation != `d:\reasonix` || |
| 44 | got.Desired.UninstallString != `"d:\reasonix\uninstall.exe"` || |
| 45 | got.Desired.DisplayIcon != `d:\reasonix\reasonix-launcher.exe` { |
| 46 | t.Fatalf("desired registration = %+v", got.Desired) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestPlanDoesNotRegisterPortableOrUnrelatedInstall(t *testing.T) { |
| 51 | tests := []struct { |
| 52 | name string |
| 53 | current *Registration |
| 54 | legacy *Registration |
| 55 | uninstall bool |
| 56 | }{ |
| 57 | {name: "portable", uninstall: false}, |
| 58 | { |
| 59 | name: "unrelated legacy install", |
| 60 | legacy: &Registration{ |
| 61 | DisplayName: "Reasonix", |
| 62 | InstallLocation: `C:\Other\Reasonix`, |
| 63 | UninstallString: `"C:\Other\Reasonix\uninstall.exe"`, |
| 64 | }, |
| 65 | uninstall: true, |
| 66 | }, |
| 67 | { |
| 68 | name: "foreign display name", |
| 69 | legacy: &Registration{ |
| 70 | DisplayName: "Another App", |
| 71 | InstallLocation: `D:\Reasonix`, |
| 72 | UninstallString: `"D:\Reasonix\uninstall.exe"`, |
| 73 | }, |
| 74 | uninstall: true, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | for _, tt := range tests { |
| 79 | t.Run(tt.name, func(t *testing.T) { |
| 80 | got, err := Plan(tt.current, tt.legacy, `D:\Reasonix`, "v1.21.0", tt.uninstall) |
| 81 | if err != nil { |
| 82 | t.Fatal(err) |
| 83 | } |
| 84 | if got.Managed || got.DeleteLegacy { |
| 85 | t.Fatalf("plan = %+v, want no registry mutation", got) |
| 86 | } |
| 87 | }) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func TestPlanRejectsInvalidInputs(t *testing.T) { |
| 92 | managed := &Registration{ |
| 93 | DisplayName: "Reasonix", |
| 94 | InstallLocation: `D:\Reasonix`, |
| 95 | UninstallString: `"D:\Reasonix\uninstall.exe"`, |
| 96 | } |
| 97 | for _, tc := range []struct { |
| 98 | root string |
| 99 | version string |
| 100 | }{ |
| 101 | {root: "", version: "v1.21.0"}, |
| 102 | {root: `D:\Reasonix`, version: ""}, |
| 103 | {root: `D:\Reasonix`, version: "dev"}, |
| 104 | } { |
| 105 | if _, err := Plan(managed, nil, tc.root, tc.version, true); err == nil { |
| 106 | t.Fatalf("Plan(%q, %q) succeeded, want error", tc.root, tc.version) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 |