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