|
| 1 | +package version |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/databricks/cli/libs/cmdio" |
| 7 | + "github.com/databricks/cli/libs/versioncheck" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func TestUpdateCheckTemplate(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + result versioncheck.Result |
| 16 | + want string |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "update available with upgrade command", |
| 20 | + result: versioncheck.Result{ |
| 21 | + CurrentVersion: "0.240.0", |
| 22 | + LatestVersion: "0.245.0", |
| 23 | + UpdateAvailable: true, |
| 24 | + InstallMethod: versioncheck.InstallHomebrew, |
| 25 | + UpgradeCommand: "brew upgrade databricks", |
| 26 | + }, |
| 27 | + want: `Databricks CLI v0.240.0 |
| 28 | +A new version is available: 0.245.0 |
| 29 | +To upgrade, run: |
| 30 | + brew upgrade databricks |
| 31 | +`, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "update available without known install method", |
| 35 | + result: versioncheck.Result{ |
| 36 | + CurrentVersion: "0.240.0", |
| 37 | + LatestVersion: "0.245.0", |
| 38 | + UpdateAvailable: true, |
| 39 | + InstallMethod: versioncheck.InstallUnknown, |
| 40 | + }, |
| 41 | + want: `Databricks CLI v0.240.0 |
| 42 | +A new version is available: 0.245.0 |
| 43 | +Download the latest release: https://github.com/databricks/cli/releases |
| 44 | +`, |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "up to date", |
| 48 | + result: versioncheck.Result{ |
| 49 | + CurrentVersion: "0.245.0", |
| 50 | + LatestVersion: "0.245.0", |
| 51 | + UpdateAvailable: false, |
| 52 | + }, |
| 53 | + want: `Databricks CLI v0.245.0 |
| 54 | +You're on the latest version. |
| 55 | +`, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "development build", |
| 59 | + result: versioncheck.Result{ |
| 60 | + CurrentVersion: "0.0.0-dev+abc123", |
| 61 | + DevelopmentBuild: true, |
| 62 | + }, |
| 63 | + want: `Databricks CLI v0.0.0-dev+abc123 |
| 64 | +This is a development build; skipping the update check. |
| 65 | +`, |
| 66 | + }, |
| 67 | + { |
| 68 | + name: "check failed", |
| 69 | + result: versioncheck.Result{ |
| 70 | + CurrentVersion: "0.240.0", |
| 71 | + CheckFailed: true, |
| 72 | + }, |
| 73 | + want: `Databricks CLI v0.240.0 |
| 74 | +Could not reach GitHub to check for a newer version. See https://github.com/databricks/cli/releases for the latest release. |
| 75 | +`, |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + for _, tt := range tests { |
| 80 | + t.Run(tt.name, func(t *testing.T) { |
| 81 | + ctx, out := cmdio.NewTestContextWithStdout(t.Context()) |
| 82 | + err := cmdio.RenderWithTemplate(ctx, tt.result, "", updateCheckTemplate) |
| 83 | + require.NoError(t, err) |
| 84 | + assert.Equal(t, tt.want, out.String()) |
| 85 | + }) |
| 86 | + } |
| 87 | +} |
0 commit comments