|
| 1 | +// Copyright 2022-2025 Salesforce, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package update |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/stretchr/testify/require" |
| 21 | +) |
| 22 | + |
| 23 | +func Test_CLI_getUpdateFileName(t *testing.T) { |
| 24 | + tests := map[string]struct { |
| 25 | + version string |
| 26 | + operatingSystem string |
| 27 | + architecture string |
| 28 | + expectedFilename string |
| 29 | + expectedErrorF string |
| 30 | + }{ |
| 31 | + "darwin production x86_64": { |
| 32 | + version: "3.4.5", |
| 33 | + operatingSystem: "darwin", |
| 34 | + architecture: "amd64", |
| 35 | + expectedFilename: "slack_cli_3.4.5_macOS_amd64.zip", |
| 36 | + }, |
| 37 | + "darwin development x86_64": { |
| 38 | + version: "3.4.5-6-badaabad", |
| 39 | + operatingSystem: "darwin", |
| 40 | + architecture: "amd64", |
| 41 | + expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_amd64.zip", |
| 42 | + }, |
| 43 | + "darwin production aarch64": { |
| 44 | + version: "3.4.5", |
| 45 | + operatingSystem: "darwin", |
| 46 | + architecture: "arm64", |
| 47 | + expectedFilename: "slack_cli_3.4.5_macOS_arm64.zip", |
| 48 | + }, |
| 49 | + "darwin development aarch64": { |
| 50 | + version: "3.4.5-6-badaabad", |
| 51 | + operatingSystem: "darwin", |
| 52 | + architecture: "arm64", |
| 53 | + expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_arm64.zip", |
| 54 | + }, |
| 55 | + "darwin production universal": { |
| 56 | + version: "3.4.5", |
| 57 | + operatingSystem: "darwin", |
| 58 | + architecture: "fallback", |
| 59 | + expectedFilename: "slack_cli_3.4.5_macOS_64-bit.zip", |
| 60 | + }, |
| 61 | + "darwin development universal": { |
| 62 | + version: "3.4.5-6-badaabad", |
| 63 | + operatingSystem: "darwin", |
| 64 | + architecture: "fallback", |
| 65 | + expectedFilename: "slack_cli_3.4.5-6-badaabad_macOS_64-bit.zip", |
| 66 | + }, |
| 67 | + "linux production x86_64": { |
| 68 | + version: "3.4.5", |
| 69 | + operatingSystem: "linux", |
| 70 | + architecture: "amd64", |
| 71 | + expectedFilename: "slack_cli_3.4.5_linux_64-bit.tar.gz", |
| 72 | + }, |
| 73 | + "linux development x86_64": { |
| 74 | + version: "3.4.5-6-badaabad", |
| 75 | + operatingSystem: "linux", |
| 76 | + architecture: "amd64", |
| 77 | + expectedFilename: "slack_cli_3.4.5-6-badaabad_linux_64-bit.tar.gz", |
| 78 | + }, |
| 79 | + "windows production x86_64": { |
| 80 | + version: "3.4.5", |
| 81 | + operatingSystem: "windows", |
| 82 | + architecture: "amd64", |
| 83 | + expectedFilename: "slack_cli_3.4.5_windows_64-bit.zip", |
| 84 | + }, |
| 85 | + "windows development x86_64": { |
| 86 | + version: "3.4.5-6-badaabad", |
| 87 | + operatingSystem: "windows", |
| 88 | + architecture: "amd64", |
| 89 | + expectedFilename: "slack_cli_3.4.5-6-badaabad_windows_64-bit.zip", |
| 90 | + }, |
| 91 | + "unknown production errors": { |
| 92 | + version: "3.4.5", |
| 93 | + operatingSystem: "dragonfly", |
| 94 | + architecture: "amd64", |
| 95 | + expectedErrorF: "auto-updating for the operating system (dragonfly) is unsupported", |
| 96 | + }, |
| 97 | + } |
| 98 | + for name, tt := range tests { |
| 99 | + t.Run(name, func(t *testing.T) { |
| 100 | + filename, err := getUpdateFileName(tt.version, tt.operatingSystem, tt.architecture) |
| 101 | + if tt.expectedErrorF != "" { |
| 102 | + require.Error(t, err) |
| 103 | + require.ErrorContains(t, err, tt.expectedErrorF) |
| 104 | + } else { |
| 105 | + require.NoError(t, err) |
| 106 | + require.Equal(t, tt.expectedFilename, filename) |
| 107 | + } |
| 108 | + }) |
| 109 | + } |
| 110 | +} |
0 commit comments