github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/difference_test.go (about) 1 // Copyright (c) 2015-2022 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "testing" 22 ) 23 24 var testCases = []struct { 25 pattern []string 26 27 srcSuffix string 28 29 match bool 30 31 typ ClientURLType 32 }{ 33 {nil, "testfile", false, objectStorage}, 34 {[]string{"test*"}, "testfile", true, objectStorage}, 35 {[]string{"file*"}, "file/abc/bcd/def", true, objectStorage}, 36 {[]string{"*"}, "file/abc/bcd/def", true, objectStorage}, 37 {[]string{""}, "file/abc/bcd/def", false, objectStorage}, 38 {[]string{"abc*"}, "file/abc/bcd/def", false, objectStorage}, 39 {[]string{"abc*", "*abc/*"}, "file/abc/bcd/def", true, objectStorage}, 40 {[]string{"*.txt"}, "file/abc/bcd/def.txt", true, objectStorage}, 41 {[]string{".*"}, ".sys", true, objectStorage}, 42 {[]string{"*."}, ".sys.", true, objectStorage}, 43 {nil, "testfile", false, fileSystem}, 44 {[]string{"test*"}, "testfile", true, fileSystem}, 45 {[]string{"file*"}, "file/abc/bcd/def", true, fileSystem}, 46 {[]string{"*"}, "file/abc/bcd/def", true, fileSystem}, 47 {[]string{""}, "file/abc/bcd/def", false, fileSystem}, 48 {[]string{"abc*"}, "file/abc/bcd/def", false, fileSystem}, 49 {[]string{"abc*", "*abc/*"}, "file/abc/bcd/def", true, fileSystem}, 50 {[]string{"abc*", "*abc/*"}, "/file/abc/bcd/def", true, fileSystem}, 51 {[]string{"*.txt"}, "file/abc/bcd/def.txt", true, fileSystem}, 52 {[]string{"*.txt"}, "/file/abc/bcd/def.txt", true, fileSystem}, 53 {[]string{".*"}, ".sys", true, fileSystem}, 54 {[]string{"*."}, ".sys.", true, fileSystem}, 55 } 56 57 func TestExcludeOptions(t *testing.T) { 58 for _, test := range testCases { 59 if matchExcludeOptions(test.pattern, test.srcSuffix, test.typ) != test.match { 60 t.Fatalf("Unexpected result %t, with pattern %s and srcSuffix %s \n", !test.match, test.pattern, test.srcSuffix) 61 } 62 } 63 }