mirror of
https://github.com/minio/minio.git
synced 2024-12-25 06:35:56 -05:00
93fd248b52
fix #11414
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
/*
|
|
* MinIO Cloud Storage, (C) 2018,2019 MinIO, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Tests ToObjectInfo function.
|
|
func TestCacheMetadataObjInfo(t *testing.T) {
|
|
m := cacheMeta{Meta: nil}
|
|
objInfo := m.ToObjectInfo("testbucket", "testobject")
|
|
if objInfo.Size != 0 {
|
|
t.Fatal("Unexpected object info value for Size", objInfo.Size)
|
|
}
|
|
if !objInfo.ModTime.Equal(time.Time{}) {
|
|
t.Fatal("Unexpected object info value for ModTime ", objInfo.ModTime)
|
|
}
|
|
if objInfo.IsDir {
|
|
t.Fatal("Unexpected object info value for IsDir", objInfo.IsDir)
|
|
}
|
|
if !objInfo.Expires.IsZero() {
|
|
t.Fatal("Unexpected object info value for Expires ", objInfo.Expires)
|
|
}
|
|
}
|
|
|
|
// test wildcard patterns for excluding entries from cache
|
|
func TestCacheExclusion(t *testing.T) {
|
|
cobjects := &cacheObjects{
|
|
cache: nil,
|
|
}
|
|
|
|
testCases := []struct {
|
|
bucketName string
|
|
objectName string
|
|
excludePattern string
|
|
expectedResult bool
|
|
}{
|
|
{"testbucket", "testobjectmatch", "testbucket/testobj*", true},
|
|
{"testbucket", "testobjectnomatch", "testbucet/testobject*", false},
|
|
{"testbucket", "testobject/pref1/obj1", "*/*", true},
|
|
{"testbucket", "testobject/pref1/obj1", "*/pref1/*", true},
|
|
{"testbucket", "testobject/pref1/obj1", "testobject/*", false},
|
|
{"photos", "image1.jpg", "*.jpg", true},
|
|
{"photos", "europe/paris/seine.jpg", "seine.jpg", false},
|
|
{"photos", "europe/paris/seine.jpg", "*/seine.jpg", true},
|
|
{"phil", "z/likes/coffee", "*/likes/*", true},
|
|
{"failbucket", "no/slash/prefixes", "/failbucket/no/", false},
|
|
{"failbucket", "no/slash/prefixes", "/failbucket/no/*", false},
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
|
cobjects.exclude = []string{testCase.excludePattern}
|
|
if cobjects.isCacheExclude(testCase.bucketName, testCase.objectName) != testCase.expectedResult {
|
|
t.Fatal("Cache exclusion test failed for case ", i)
|
|
}
|
|
}
|
|
}
|