1 # -*- encoding: binary -*-
2 # Copyright (C) 2012-2017 all contributors <omgdav-public@bogomips.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 require './test/integration'
5 class TestMtime < Minitest::Test
6 include TestMogileFSIntegration
9 assert_equal 201, req("MKCOL", "/a")[0].to_i
10 assert_equal 201, req("MKCOL", "/a/b")[0].to_i
12 before = @db[:paths].where(name: "a").to_a
13 assert_equal before.size, 1
14 before_mtime = Time.at(before[0][:mtime])
15 assert_in_delta before_mtime, now, 2
17 # creating a new directory sets mtime in parent (only), not grandparent
19 assert_equal 201, req("MKCOL", "/a/b/c")[0].to_i
20 after = @db[:paths].where(name: "a").to_a
21 assert_equal after.size, 1
22 after_mtime = Time.at(after[0][:mtime])
23 assert_equal before_mtime, after_mtime
25 # creating a new file sets mtime in parent (only), not grandparent
27 resp = @req.put("/a/b/f", input: StringIO.new("HELLO"))
28 assert_equal 201, resp.status.to_i
29 after = @db[:paths].where(name: "a").to_a
30 assert_equal after.size, 1
31 after_mtime = Time.at(after[0][:mtime])
32 assert_equal before_mtime, after_mtime
34 b = @db[:paths].where(name: "b").to_a
35 f = @db[:paths].where(name: "f").to_a
36 assert_equal b.size, 1
37 assert_equal f.size, 1
38 assert_equal b[0][:mtime], f[0][:mtime]
40 # updating existing file should not change mtime
42 resp = @req.put("/a/b/f", input: StringIO.new("HELLO"))
43 assert_equal 204, resp.status.to_i
44 f = @db[:paths].where(name: "f").to_a
45 assert_equal f.size, 1
46 assert_operator f[0][:mtime], :>, b[0][:mtime]
48 bb = @db[:paths].where(name: "b").to_a
49 assert_equal bb.size, 1
50 assert_equal bb[0][:mtime], b[0][:mtime]