|
| 1 | +// Copyright 2026 Matrix Origin |
| 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 main |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/stretchr/testify/require" |
| 21 | +) |
| 22 | + |
| 23 | +func TestNormalizeLegacyRemoteS3Args(t *testing.T) { |
| 24 | + remoteArgs := "bucket=test,endpoint=http://minio:9000,region=us-east-1,key-prefix=data,key-id=id,key-secret=secret" |
| 25 | + tests := []struct { |
| 26 | + name string |
| 27 | + args []string |
| 28 | + want []string |
| 29 | + }{ |
| 30 | + { |
| 31 | + name: "separate legacy argument", |
| 32 | + args: []string{"ckp", "list", "--backend=S3", "--s3", remoteArgs}, |
| 33 | + want: []string{"ckp", "list", "--backend=S3", "--remote-s3", remoteArgs}, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: "joined legacy argument", |
| 37 | + args: []string{"ckp", "dump", "--s3=" + remoteArgs}, |
| 38 | + want: []string{"ckp", "dump", "--remote-s3=" + remoteArgs}, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "bucket with default AWS settings", |
| 42 | + args: []string{"ckp", "list", "--s3", "bucket=test"}, |
| 43 | + want: []string{"ckp", "list", "--remote-s3", "bucket=test"}, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "local S3FS selector", |
| 47 | + args: []string{"ckp", "list", "--s3", "/tmp/mo-data"}, |
| 48 | + want: []string{"ckp", "list", "--s3", "/tmp/mo-data"}, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "current remote argument", |
| 52 | + args: []string{"ckp", "list", "--remote-s3", remoteArgs}, |
| 53 | + want: []string{"ckp", "list", "--remote-s3", remoteArgs}, |
| 54 | + }, |
| 55 | + { |
| 56 | + name: "other command", |
| 57 | + args: []string{"object", "stat", "--s3", remoteArgs}, |
| 58 | + want: []string{"object", "stat", "--s3", remoteArgs}, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + for _, test := range tests { |
| 63 | + t.Run(test.name, func(t *testing.T) { |
| 64 | + original := append([]string(nil), test.args...) |
| 65 | + require.Equal(t, test.want, normalizeLegacyRemoteS3Args(test.args)) |
| 66 | + require.Equal(t, original, test.args) |
| 67 | + }) |
| 68 | + } |
| 69 | +} |
0 commit comments