github.com/abemedia/appcast@v0.4.0/integrations/appinstaller/build_test.go (about) 1 package appinstaller_test 2 3 import ( 4 "context" 5 "io" 6 "testing" 7 8 "github.com/abemedia/appcast/integrations/appinstaller" 9 source "github.com/abemedia/appcast/source/file" 10 target "github.com/abemedia/appcast/target/file" 11 "github.com/google/go-cmp/cmp" 12 ) 13 14 func TestBuild(t *testing.T) { 15 src, _ := source.New(source.Config{Path: "../../testdata", URL: "https://dl.example.com/"}) 16 tgt, _ := target.New(target.Config{Path: t.TempDir(), URL: "https://example.com"}) 17 18 tests := []struct { 19 name string 20 config *appinstaller.Config 21 want string 22 }{ 23 { 24 name: "Test-x64.appinstaller", 25 config: &appinstaller.Config{ 26 Source: src, 27 Target: tgt, 28 }, 29 want: `<?xml version="1.0" encoding="UTF-8"?> 30 <AppInstaller xmlns="http://schemas.microsoft.com/appx/appinstaller/2017" Version="1.0.0.1" Uri="https://example.com/Test-x64.appinstaller"> 31 <MainPackage Name="Test" Publisher="CN=Test" Version="1.0.0.1" ProcessorArchitecture="x64" Uri="https://dl.example.com/v1.0.0/test.msix" /> 32 </AppInstaller>`, 33 }, 34 { 35 name: "Test.appinstaller", 36 config: &appinstaller.Config{ 37 Source: src, 38 Target: tgt, 39 OnLaunch: &appinstaller.OnLaunchConfig{ 40 ShowPrompt: true, 41 }, 42 }, 43 want: `<?xml version="1.0" encoding="UTF-8"?> 44 <AppInstaller xmlns="http://schemas.microsoft.com/appx/appinstaller/2018" Version="1.0.0.1" Uri="https://example.com/Test.appinstaller"> 45 <MainBundle Name="Test" Publisher="CN=Test" Version="1.0.0.1" Uri="https://dl.example.com/v1.0.0/test.msixbundle" /> 46 <UpdateSettings> 47 <OnLaunch ShowPrompt="true" /> 48 </UpdateSettings> 49 </AppInstaller>`, 50 }, 51 { 52 name: "Test-x64.appinstaller", 53 config: &appinstaller.Config{ 54 Source: src, 55 Target: tgt, 56 AutomaticBackgroundTask: true, 57 }, 58 want: `<?xml version="1.0" encoding="UTF-8"?> 59 <AppInstaller xmlns="http://schemas.microsoft.com/appx/appinstaller/2017/2" Version="1.0.0.1" Uri="https://example.com/Test-x64.appinstaller"> 60 <MainPackage Name="Test" Publisher="CN=Test" Version="1.0.0.1" ProcessorArchitecture="x64" Uri="https://dl.example.com/v1.0.0/test.msix" /> 61 <UpdateSettings> 62 <AutomaticBackgroundTask /> 63 </UpdateSettings> 64 </AppInstaller>`, 65 }, 66 { 67 name: "Test-x64.appinstaller", 68 config: &appinstaller.Config{ 69 Source: src, 70 Target: tgt, 71 OnLaunch: &appinstaller.OnLaunchConfig{ 72 HoursBetweenUpdateChecks: 12, 73 UpdateBlocksActivation: true, 74 ShowPrompt: true, 75 }, 76 AutomaticBackgroundTask: true, 77 ForceUpdateFromAnyVersion: true, 78 }, 79 want: `<?xml version="1.0" encoding="UTF-8"?> 80 <AppInstaller xmlns="http://schemas.microsoft.com/appx/appinstaller/2018" Version="1.0.0.1" Uri="https://example.com/Test-x64.appinstaller"> 81 <MainPackage Name="Test" Publisher="CN=Test" Version="1.0.0.1" ProcessorArchitecture="x64" Uri="https://dl.example.com/v1.0.0/test.msix" /> 82 <UpdateSettings> 83 <OnLaunch HoursBetweenUpdateChecks="12" ShowPrompt="true" UpdateBlocksActivation="true" /> 84 <AutomaticBackgroundTask /> 85 <ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion> 86 </UpdateSettings> 87 </AppInstaller>`, 88 }, 89 { 90 name: "Test.appinstaller", 91 config: &appinstaller.Config{ 92 Source: src, 93 Target: tgt, 94 UploadPackages: true, 95 }, 96 want: `<?xml version="1.0" encoding="UTF-8"?> 97 <AppInstaller xmlns="http://schemas.microsoft.com/appx/appinstaller/2017" Version="1.0.0.1" Uri="https://example.com/Test.appinstaller"> 98 <MainBundle Name="Test" Publisher="CN=Test" Version="1.0.0.1" Uri="https://example.com/test.msixbundle" /> 99 </AppInstaller>`, 100 }, 101 } 102 103 for _, test := range tests { 104 err := appinstaller.Build(context.Background(), test.config) 105 if err != nil { 106 t.Fatal(err) 107 } 108 109 r, err := test.config.Target.NewReader(context.Background(), test.name) 110 if err != nil { 111 t.Fatal(err) 112 } 113 defer r.Close() 114 115 got, err := io.ReadAll(r) 116 if err != nil { 117 t.Fatal(err) 118 } 119 120 if diff := cmp.Diff(test.want, string(got)); diff != "" { 121 t.Fatal(diff) 122 } 123 124 if test.config.UploadPackages { 125 for _, ext := range []string{".msixbundle", ".msix"} { 126 if _, err = tgt.NewReader(context.Background(), "test"+ext); err != nil { 127 t.Fatal(err) 128 } 129 } 130 } 131 } 132 }