github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/test/archive_test.go (about) 1 // Copyright 2018 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package test 6 7 import ( 8 "testing" 9 "time" 10 ) 11 12 func TestArchiveByRevision(t *testing.T) { 13 test(t, 14 users("alice", "bob"), 15 16 inPrivateTlf("alice,bob"), 17 as(alice, 18 mkdir("a"), 19 ), 20 as(alice, 21 lsdir("", m{"a$": "DIR"}), 22 lsdir("a", m{}), 23 ), 24 as(bob, 25 lsdir("", m{"a$": "DIR"}), 26 lsdir("a", m{}), 27 ), 28 29 inPrivateTlfAtRevision("alice,bob", 1), 30 as(alice, 31 lsdir("", m{}), 32 ), 33 as(bob, 34 lsdir("", m{}), 35 ), 36 ) 37 } 38 39 func TestArchiveByTime(t *testing.T) { 40 // The start time of the test is 1970-01-01 00:00:01 +0000 UTC. 41 rev1checks := []optionOp{ 42 as(alice, 43 lsdir("", m{}), 44 ), 45 as(bob, 46 lsdir("", m{}), 47 ), 48 } 49 50 rev2checks := []optionOp{ 51 as(alice, 52 lsdir("", m{"a$": "DIR"}), 53 lsdir("a", m{}), 54 ), 55 as(bob, 56 lsdir("", m{"a$": "DIR"}), 57 lsdir("a", m{}), 58 ), 59 } 60 61 test(t, 62 users("alice", "bob"), 63 64 inPrivateTlf("alice,bob"), 65 rev1checks[0], rev1checks[1], 66 as(alice, 67 addTime(365*24*time.Hour), 68 mkdir("a"), 69 ), 70 rev2checks[0], rev2checks[1], 71 72 // Try various formats for the first revision. 73 inPrivateTlfAtTime("alice,bob", "02 Jan 1970"), 74 rev1checks[0], rev1checks[1], 75 76 inPrivateTlfAtTime("alice,bob", "April 4, 1970"), 77 rev1checks[0], rev1checks[1], 78 79 inPrivateTlfAtTime("alice,bob", "1970.09"), 80 rev1checks[0], rev1checks[1], 81 82 // Now the second revision. 83 inPrivateTlfAtTime("alice,bob", "02 Jan 1971"), 84 rev2checks[0], rev2checks[1], 85 86 inPrivateTlfAtTime("alice,bob", "April 4, 1980"), 87 rev2checks[0], rev2checks[1], 88 89 inPrivateTlfAtTime("alice,bob", "2018.09"), 90 rev2checks[0], rev2checks[1], 91 ) 92 } 93 94 func TestArchiveByTimeWithColons(t *testing.T) { 95 // The start time of the test is 1970-01-01 00:00:01 +0000 UTC. 96 rev1checks := []optionOp{ 97 as(alice, 98 lsdir("", m{}), 99 ), 100 as(bob, 101 lsdir("", m{}), 102 ), 103 } 104 105 rev2checks := []optionOp{ 106 as(alice, 107 lsdir("", m{"a$": "DIR"}), 108 lsdir("a", m{}), 109 ), 110 as(bob, 111 lsdir("", m{"a$": "DIR"}), 112 lsdir("a", m{}), 113 ), 114 } 115 116 test(t, 117 skip("dokan", "windows doesn't support colons in filenames"), 118 users("alice", "bob"), 119 120 inPrivateTlf("alice,bob"), 121 rev1checks[0], rev1checks[1], 122 as(alice, 123 addTime(365*24*time.Hour), 124 mkdir("a"), 125 ), 126 rev2checks[0], rev2checks[1], 127 128 // Try various formats for the first revision. 129 inPrivateTlfAtTime("alice,bob", "1970-08-12T22:15:09Z"), 130 rev1checks[0], rev1checks[1], 131 132 inPrivateTlfAtTime("alice,bob", "Fri Jan 2 15:04:05 1970"), 133 rev1checks[0], rev1checks[1], 134 135 // Now the second revision. 136 inPrivateTlfAtTime("alice,bob", "2001-08-12T22:15:09Z"), 137 rev2checks[0], rev2checks[1], 138 139 inPrivateTlfAtTime("alice,bob", "Tue Jan 2 15:04:05 2018"), 140 rev2checks[0], rev2checks[1], 141 ) 142 } 143 144 func TestArchiveByRelativeTime(t *testing.T) { 145 // The start time of the test is 1970-01-01 00:00:01 +0000 UTC. 146 rev1checks := []optionOp{ 147 as(alice, 148 lsdir("", m{}), 149 ), 150 as(bob, 151 lsdir("", m{}), 152 ), 153 } 154 155 rev2checks := []optionOp{ 156 as(alice, 157 lsdir("", m{"a$": "DIR"}), 158 lsdir("a", m{}), 159 ), 160 as(bob, 161 lsdir("", m{"a$": "DIR"}), 162 lsdir("a", m{}), 163 ), 164 } 165 166 test(t, 167 users("alice", "bob"), 168 169 inPrivateTlf("alice,bob"), 170 rev1checks[0], rev1checks[1], 171 as(alice, 172 addTime(365*24*time.Hour), 173 mkdir("a"), 174 ), 175 rev2checks[0], rev2checks[1], 176 177 as(alice, 178 addTime(30*time.Second), 179 ), 180 181 // Try various formats for the first revision. 182 inPrivateTlfAtRelativeTime("alice,bob", "1h"), 183 rev1checks[0], rev1checks[1], 184 185 inPrivateTlfAtRelativeTime("alice,bob", "3600s"), 186 rev1checks[0], rev1checks[1], 187 188 inPrivateTlfAtRelativeTime("alice,bob", "5h55m"), 189 rev1checks[0], rev1checks[1], 190 191 // Now the second revision. 192 inPrivateTlfAtRelativeTime("alice,bob", "1s"), 193 rev2checks[0], rev2checks[1], 194 195 inPrivateTlfAtRelativeTime("alice,bob", "15s"), 196 rev2checks[0], rev2checks[1], 197 198 // Make sure the relative time adjusts with the clock. 199 as(alice, 200 addTime(1*time.Hour), 201 ), 202 inPrivateTlfAtRelativeTime("alice,bob", "1h"), 203 rev2checks[0], rev2checks[1], 204 ) 205 }