(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestCheckVersion(t *testing.T) { |
| 16 | isDevBuild = false |
| 17 | |
| 18 | t.Run("skip_if_devbox_cloud", func(t *testing.T) { |
| 19 | defer os.Unsetenv(envName) |
| 20 | // if devbox cloud |
| 21 | t.Setenv(envir.DevboxRegion, "true") |
| 22 | buf := new(bytes.Buffer) |
| 23 | CheckVersion(buf, "devbox shell") |
| 24 | if buf.String() != "" { |
| 25 | t.Errorf("expected empty string, got %q", buf.String()) |
| 26 | } |
| 27 | t.Setenv(envir.DevboxRegion, "") |
| 28 | }) |
| 29 | |
| 30 | // no launcher version or latest-version env var |
| 31 | t.Run("skip_if_no_launcher_version_or_latest_version", func(t *testing.T) { |
| 32 | defer os.Unsetenv(envName) |
| 33 | t.Setenv(envir.LauncherVersion, "") |
| 34 | t.Setenv(envir.DevboxLatestVersion, "") |
| 35 | buf := new(bytes.Buffer) |
| 36 | CheckVersion(buf, "devbox shell") |
| 37 | if buf.String() != "" { |
| 38 | t.Errorf("expected empty string, got %q", buf.String()) |
| 39 | } |
| 40 | }) |
| 41 | |
| 42 | t.Run("print_if_launcher_version_outdated", func(t *testing.T) { |
| 43 | defer os.Unsetenv(envName) |
| 44 | // set older launcher version |
| 45 | t.Setenv(envir.LauncherVersion, "v0.1.0") |
| 46 | |
| 47 | buf := new(bytes.Buffer) |
| 48 | CheckVersion(buf, "devbox shell") |
| 49 | if !strings.Contains(buf.String(), "New launcher available") { |
| 50 | t.Errorf("expected notice about new launcher version, got %q", buf.String()) |
| 51 | } |
| 52 | }) |
| 53 | |
| 54 | t.Run("print_if_binary_version_outdated", func(t *testing.T) { |
| 55 | defer os.Unsetenv(envName) |
| 56 | // set the launcher version so that it is not outdated |
| 57 | t.Setenv(envir.LauncherVersion, strings.TrimPrefix(expectedLauncherVersion, "v")) |
| 58 | |
| 59 | // set the latest version to be greater the current binary version |
| 60 | t.Setenv(envir.DevboxLatestVersion, "0.4.9") |
| 61 | |
| 62 | // mock the existing binary version |
| 63 | currentDevboxVersion = "v0.4.8" |
| 64 | |
| 65 | buf := new(bytes.Buffer) |
| 66 | CheckVersion(buf, "devbox shell") |
| 67 | if !strings.Contains(buf.String(), "New devbox available") { |
| 68 | t.Errorf("expected notice about new devbox version, got %q", buf.String()) |
| 69 | } |
| 70 | }) |
| 71 | |
| 72 | t.Run("skip_if_all_versions_up_to_date", func(t *testing.T) { |
nothing calls this directly
no test coverage detected