8784: Fix test for latest firefox.
[arvados.git] / sdk / ruby / test / sdk_fixtures.rb
1 require "yaml"
2
3 module SDKFixtures
4   module StaticMethods
5     # SDKFixtures will use these as class methods, and install them as
6     # instance methods on the test classes.
7     def random_block(size=nil)
8       sprintf("%032x+%d", rand(16 ** 32), size || rand(64 * 1024 * 1024))
9     end
10
11     def random_blocks(count, size=nil)
12       (0...count).map { |_| random_block(size) }
13     end
14   end
15
16   extend StaticMethods
17
18   def self.included(base)
19     base.include(StaticMethods)
20   end
21
22   @@fixtures = {}
23   def fixtures name
24     @@fixtures[name] ||=
25       begin
26         path = File.
27           expand_path("../../../../services/api/test/fixtures/#{name}.yml",
28                       __FILE__)
29         file = IO.read(path)
30         trim_index = file.index('# Test Helper trims the rest of the file')
31         file = file[0, trim_index] if trim_index
32         YAML.load(file)
33       end
34   end
35
36   ### Valid manifests
37   SIMPLEST_MANIFEST = ". #{random_block(9)} 0:9:simple.txt\n"
38   MULTIBLOCK_FILE_MANIFEST =
39     [". #{random_block(8)} 0:4:repfile 4:4:uniqfile",
40      "./s1 #{random_block(6)} 0:3:repfile 3:3:uniqfile",
41      ". #{random_block(8)} 0:7:uniqfile2 7:1:repfile\n"].join("\n")
42   MULTILEVEL_MANIFEST =
43     [". #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n",
44      "./dir0 #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n",
45      "./dir0/subdir #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n",
46      "./dir1 #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n",
47      "./dir1/subdir #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n",
48      "./dir2 #{random_block(9)} 0:3:file1 3:3:file2 6:3:file3\n"].join("")
49   COLON_FILENAME_MANIFEST = ". #{random_block(9)} 0:9:file:test.txt\n"
50   # Filename is `a a.txt`.
51   ESCAPED_FILENAME_MANIFEST = ". #{random_block(9)} 0:9:a\\040\\141.txt\n"
52   MANY_ESCAPES_MANIFEST =
53     "./dir\\040name #{random_block(9)} 0:9:file\\\\name\\011\\here.txt\n"
54   NONNORMALIZED_MANIFEST =
55     ["./dir2 #{random_block} 0:0:z 0:0:y 0:0:x",
56      "./dir1 #{random_block} 0:0:p 0:0:o 0:0:n\n"].join("\n")
57   MANIFEST_WITH_DIRS_IN_FILENAMES =
58     [". #{random_block(10)} 0:3:file1 3:3:dir1/file1 6:3:dir1/dir2/file1\n"].join("")
59   MULTILEVEL_MANIFEST_WITH_DIRS_IN_FILENAMES =
60     [". #{random_block(10)} 0:3:file1 3:3:dir1/file1 6:4:dir1/dir2/file1\n",
61      "./dir1 #{random_block(10)} 0:3:file1 3:7:dir2/file1\n"].join("")
62
63   ### Non-tree manifests
64   # These manifests follow the spec, but they express a structure that can't
65   # can't be represented by a POSIX filesystem tree.  For example, there's a
66   # name conflict between a stream and a filename.
67   NAME_CONFLICT_MANIFEST =
68     [". #{random_block(9)} 0:9:conflict",
69      "./conflict #{random_block} 0:0:name\n"].join("\n")
70 end