2018-03-28 23:14:06 +02:00
|
|
|
/*
|
2019-08-10 02:09:08 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2018,2019 MinIO, Inc.
|
2018-03-28 23:14:06 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2021-02-12 04:25:47 +01:00
|
|
|
"time"
|
2018-03-28 23:14:06 +02:00
|
|
|
)
|
|
|
|
|
2019-08-10 02:09:08 +02:00
|
|
|
// 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)
|
|
|
|
}
|
2021-02-12 04:25:47 +01:00
|
|
|
if !objInfo.ModTime.Equal(time.Time{}) {
|
2019-08-10 02:09:08 +02:00
|
|
|
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)
|
2018-03-28 23:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test wildcard patterns for excluding entries from cache
|
|
|
|
func TestCacheExclusion(t *testing.T) {
|
2019-07-11 00:41:11 +02:00
|
|
|
cobjects := &cacheObjects{
|
|
|
|
cache: nil,
|
2018-03-28 23:14:06 +02:00
|
|
|
}
|
2019-07-11 00:41:11 +02:00
|
|
|
|
2018-03-28 23:14:06 +02:00
|
|
|
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 {
|
2019-07-11 00:41:11 +02:00
|
|
|
cobjects.exclude = []string{testCase.excludePattern}
|
|
|
|
if cobjects.isCacheExclude(testCase.bucketName, testCase.objectName) != testCase.expectedResult {
|
2018-03-28 23:14:06 +02:00
|
|
|
t.Fatal("Cache exclusion test failed for case ", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|