github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/fs/mut_test.go (about) 1 // +build linux darwin 2 3 /* 4 Copyright 2014 Google Inc. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package fs 20 21 import ( 22 "testing" 23 "time" 24 ) 25 26 func TestDeleteEligibility(t *testing.T) { 27 tests := []struct { 28 name string 29 ts time.Time 30 exp bool 31 }{ 32 {"zero", time.Time{}, true}, 33 {"now", time.Now(), false}, 34 {"future", time.Now().Add(time.Hour), false}, 35 {"recent", time.Now().Add(-(deletionRefreshWindow / 2)), false}, 36 {"past", time.Now().Add(-(deletionRefreshWindow * 2)), true}, 37 } 38 39 for _, test := range tests { 40 d := &mutDir{localCreateTime: test.ts} 41 if d.eligibleToDelete() != test.exp { 42 t.Errorf("Expected %v %T/%v", test.exp, d, test.name) 43 } 44 f := &mutFile{localCreateTime: test.ts} 45 if f.eligibleToDelete() != test.exp { 46 t.Errorf("Expected %v for %T/%v", test.exp, f, test.name) 47 } 48 } 49 }