|
| 1 | +--- |
| 2 | +sidebar_position: 6 |
| 3 | +--- |
| 4 | + |
| 5 | +# Testing Updates |
| 6 | +<AppliesTo all /> |
| 7 | + |
| 8 | +When developing applications with Velopack, you'll want to test your update logic without requiring a full installation. This guide shows you how to test updates, hooks, and other Velopack features in development and CI/CD environments. |
| 9 | + |
| 10 | +## Testing in Development |
| 11 | + |
| 12 | +The simplest way to test Velopack integration during development is to use the built-in test helpers provided by the SDK. |
| 13 | + |
| 14 | +### C# - TestVelopackLocator |
| 15 | + |
| 16 | +The `TestVelopackLocator` class allows you to mock a Velopack installation: |
| 17 | + |
| 18 | +```csharp |
| 19 | +var locator = new TestVelopackLocator( |
| 20 | + appId: "MyApp", |
| 21 | + version: "1.0.0", |
| 22 | + packagesDir: "/path/to/packages" |
| 23 | +); |
| 24 | + |
| 25 | +VelopackApp.Build() |
| 26 | + .SetLocator(locator) |
| 27 | + .Run(); |
| 28 | +``` |
| 29 | + |
| 30 | +You can then test update checking and downloading: |
| 31 | + |
| 32 | +```csharp |
| 33 | +var updateManager = new UpdateManager(source, null, locator); |
| 34 | +var updateInfo = await updateManager.CheckForUpdatesAsync(); |
| 35 | + |
| 36 | +if (updateInfo != null) { |
| 37 | + await updateManager.DownloadUpdatesAsync(updateInfo); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Other Languages |
| 42 | + |
| 43 | +For languages without a built-in test locator, you can test by: |
| 44 | + |
| 45 | +1. **Creating a minimal package** - Build a test release with `vpk pack` and install it locally |
| 46 | +2. **Using a local update source** - Point your UpdateManager at a local directory |
| 47 | +3. **Mocking the update source** - Create a mock HTTP server or file source for testing |
| 48 | + |
| 49 | +## Testing Update Downloads |
| 50 | + |
| 51 | +To test that your application can correctly check for and download updates: |
| 52 | + |
| 53 | +```csharp |
| 54 | +// Create a mock update source |
| 55 | +var source = new SimpleWebSource("http://localhost:8080/releases"); |
| 56 | + |
| 57 | +// Or use a local directory |
| 58 | +var source = new SimpleWebSource("file:///C:/my-test-updates"); |
| 59 | + |
| 60 | +var updateManager = new UpdateManager(source); |
| 61 | +var updateInfo = await updateManager.CheckForUpdatesAsync(); |
| 62 | + |
| 63 | +Assert.NotNull(updateInfo); |
| 64 | +Assert.True(updateInfo.TargetFullRelease.Version > currentVersion); |
| 65 | + |
| 66 | +await updateManager.DownloadUpdatesAsync(updateInfo); |
| 67 | +``` |
| 68 | + |
| 69 | +## Testing Channels |
| 70 | + |
| 71 | +Test [channel switching](./switching-channels.mdx) by explicitly specifying a channel: |
| 72 | + |
| 73 | +```csharp |
| 74 | +var options = new UpdateOptions { |
| 75 | + ExplicitChannel = "beta", |
| 76 | + AllowVersionDowngrade = true |
| 77 | +}; |
| 78 | + |
| 79 | +var updateManager = new UpdateManager(source, options); |
| 80 | +var updateInfo = await updateManager.CheckForUpdatesAsync(); |
| 81 | +``` |
| 82 | + |
| 83 | +Read more about channels in the [Channels documentation](../packaging/channels.mdx). |
| 84 | + |
| 85 | +## Testing Hooks |
| 86 | + |
| 87 | +To test install/update/uninstall hooks without going through a full install: |
| 88 | + |
| 89 | +**Option 1: Run your app with hook arguments** |
| 90 | + |
| 91 | +```bash |
| 92 | +MyApp.exe --veloapp-install 1.0.0 |
| 93 | +MyApp.exe --veloapp-updated 1.1.0 |
| 94 | +MyApp.exe --veloapp-uninstall 1.0.0 |
| 95 | +``` |
| 96 | + |
| 97 | +Your app should handle these arguments and exit quickly. |
| 98 | + |
| 99 | +**Option 2: Set environment variables** |
| 100 | + |
| 101 | +```bash |
| 102 | +# Windows |
| 103 | +$env:VELOPACK_FIRSTRUN="true" |
| 104 | +.\MyApp.exe |
| 105 | + |
| 106 | +# Linux/macOS |
| 107 | +VELOPACK_FIRSTRUN=true ./MyApp |
| 108 | +``` |
| 109 | + |
| 110 | +See the [Hooks documentation](./hooks.mdx) for more details on available hooks. |
| 111 | + |
| 112 | +## Testing in CI/CD |
| 113 | + |
| 114 | +You can verify your Velopack integration in automated tests without a full installation. |
| 115 | + |
| 116 | +### Unit Testing Example (C#) |
| 117 | + |
| 118 | +```csharp |
| 119 | +[Fact] |
| 120 | +public async Task CanCheckForUpdates() |
| 121 | +{ |
| 122 | + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); |
| 123 | + Directory.CreateDirectory(tempDir); |
| 124 | + |
| 125 | + try { |
| 126 | + var locator = new TestVelopackLocator("TestApp", "1.0.0", tempDir); |
| 127 | + var source = new SimpleWebSource("https://my-updates.com"); |
| 128 | + var updateManager = new UpdateManager(source, null, locator); |
| 129 | + |
| 130 | + var updateInfo = await updateManager.CheckForUpdatesAsync(); |
| 131 | + // Assert your expectations |
| 132 | + } finally { |
| 133 | + Directory.Delete(tempDir, true); |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +## Common Testing Scenarios |
| 139 | + |
| 140 | +### Test Version Downgrade |
| 141 | + |
| 142 | +```csharp |
| 143 | +var options = new UpdateOptions { AllowVersionDowngrade = true }; |
| 144 | +var updateManager = new UpdateManager(source, options, locator); |
| 145 | +``` |
| 146 | + |
| 147 | +### Test First Run Detection |
| 148 | + |
| 149 | +```csharp |
| 150 | +VelopackApp.Build() |
| 151 | + .OnFirstRun((v) => { |
| 152 | + // This code runs only on first launch after install |
| 153 | + Console.WriteLine($"First run of version {v}"); |
| 154 | + }) |
| 155 | + .Run(); |
| 156 | +``` |
| 157 | + |
| 158 | +### Test Update Restart |
| 159 | + |
| 160 | +```csharp |
| 161 | +VelopackApp.Build() |
| 162 | + .OnAfterUpdateFastCallback((v) => { |
| 163 | + // This runs after an update is applied |
| 164 | + Console.WriteLine($"Updated to version {v}"); |
| 165 | + }) |
| 166 | + .Run(); |
| 167 | +``` |
| 168 | + |
| 169 | +## Debugging Tips |
| 170 | + |
| 171 | +When testing updates: |
| 172 | + |
| 173 | +1. **Check logs** - Enable logging to see what Velopack is doing |
| 174 | +2. **Inspect packages directory** - Verify packages are downloaded correctly |
| 175 | +3. **Check release feed** - Ensure your `releases.{channel}.json` is valid |
| 176 | + |
| 177 | +For more debugging guidance, see the [Debugging documentation](../troubleshooting/debugging.mdx). |
0 commit comments