|
| 1 | +/* |
| 2 | +Copyright 2026 The Vitess Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package mysqlctl |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | +) |
| 24 | + |
| 25 | +func TestResolveExternalDecompressor(t *testing.T) { |
| 26 | + tests := []struct { |
| 27 | + name string |
| 28 | + cliDecompressorCmd string |
| 29 | + useManifest bool |
| 30 | + manifestDecompressor string |
| 31 | + expected string |
| 32 | + }{ |
| 33 | + { |
| 34 | + name: "CLI flag takes precedence over manifest", |
| 35 | + cliDecompressorCmd: "zstd -d", |
| 36 | + useManifest: true, |
| 37 | + manifestDecompressor: "gzip -d", |
| 38 | + expected: "zstd -d", |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "CLI flag takes precedence even when use-manifest is false", |
| 42 | + cliDecompressorCmd: "zstd -d", |
| 43 | + useManifest: false, |
| 44 | + manifestDecompressor: "gzip -d", |
| 45 | + expected: "zstd -d", |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "manifest used when use-manifest is true and no CLI flag", |
| 49 | + cliDecompressorCmd: "", |
| 50 | + useManifest: true, |
| 51 | + manifestDecompressor: "gzip -d", |
| 52 | + expected: "gzip -d", |
| 53 | + }, |
| 54 | + { |
| 55 | + name: "manifest ignored when use-manifest is false", |
| 56 | + cliDecompressorCmd: "", |
| 57 | + useManifest: false, |
| 58 | + manifestDecompressor: "gzip -d", |
| 59 | + expected: "", |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "empty when nothing is set", |
| 63 | + cliDecompressorCmd: "", |
| 64 | + useManifest: false, |
| 65 | + manifestDecompressor: "", |
| 66 | + expected: "", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "empty when use-manifest is true but manifest is empty", |
| 70 | + cliDecompressorCmd: "", |
| 71 | + useManifest: true, |
| 72 | + manifestDecompressor: "", |
| 73 | + expected: "", |
| 74 | + }, |
| 75 | + } |
| 76 | + |
| 77 | + for _, tt := range tests { |
| 78 | + t.Run(tt.name, func(t *testing.T) { |
| 79 | + origCmd := ExternalDecompressorCmd |
| 80 | + origAllow := ExternalDecompressorUseManifest |
| 81 | + t.Cleanup(func() { |
| 82 | + ExternalDecompressorCmd = origCmd |
| 83 | + ExternalDecompressorUseManifest = origAllow |
| 84 | + }) |
| 85 | + |
| 86 | + ExternalDecompressorCmd = tt.cliDecompressorCmd |
| 87 | + ExternalDecompressorUseManifest = tt.useManifest |
| 88 | + |
| 89 | + result := resolveExternalDecompressor(tt.manifestDecompressor) |
| 90 | + assert.Equal(t, tt.expected, result) |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments