This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgzip-spec.coffee
166 lines (148 loc) · 7.01 KB
/
gzip-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
archive = require '../lib/ls-archive'
path = require 'path'
describe "gzipped tar files", ->
fixturesRoot = null
beforeEach ->
fixturesRoot = path.join(__dirname, 'fixtures')
describe ".list()", ->
describe "when the archive file exists", ->
it "returns files in the gzipped tar archive", ->
gzipPaths = null
callback = (error, paths) -> gzipPaths = paths
archive.list(path.join(fixturesRoot, 'one-file.tar.gz'), callback)
waitsFor -> gzipPaths?
runs ->
expect(gzipPaths.length).toBe 1
expect(gzipPaths[0].path).toBe 'file.txt'
expect(gzipPaths[0].isDirectory()).toBe false
expect(gzipPaths[0].isFile()).toBe true
expect(gzipPaths[0].isSymbolicLink()).toBe false
it "returns files in the gzipped tar archive", ->
gzipPaths = null
callback = (error, paths) -> gzipPaths = paths
archive.list(path.join(fixturesRoot, 'one-file.tgz'), callback)
waitsFor -> gzipPaths?
runs ->
expect(gzipPaths.length).toBe 1
expect(gzipPaths[0].path).toBe 'file.txt'
expect(gzipPaths[0].isDirectory()).toBe false
expect(gzipPaths[0].isFile()).toBe true
expect(gzipPaths[0].isSymbolicLink()).toBe false
it "returns folders in the gzipped tar archive", ->
gzipPaths = null
callback = (error, paths) -> gzipPaths = paths
archive.list(path.join(fixturesRoot, 'one-folder.tar.gz'), callback)
waitsFor -> gzipPaths?
runs ->
expect(gzipPaths.length).toBe 1
expect(gzipPaths[0].path).toBe 'folder'
expect(gzipPaths[0].isDirectory()).toBe true
expect(gzipPaths[0].isFile()).toBe false
expect(gzipPaths[0].isSymbolicLink()).toBe false
it "returns folders in the gzipped tar archive", ->
gzipPaths = null
callback = (error, paths) -> gzipPaths = paths
archive.list(path.join(fixturesRoot, 'one-folder.tgz'), callback)
waitsFor -> gzipPaths?
runs ->
expect(gzipPaths.length).toBe 1
expect(gzipPaths[0].path).toBe 'folder'
expect(gzipPaths[0].isDirectory()).toBe true
expect(gzipPaths[0].isFile()).toBe false
expect(gzipPaths[0].isSymbolicLink()).toBe false
describe "when the archive path does not exist", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'not-a-file.tar.gz')
pathError = null
callback = (error) -> pathError = error
archive.list(archivePath, callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe "when the archive path isn't a valid gzipped tar file", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'invalid.tar.gz')
pathError = null
callback = (error) -> pathError = error
archive.list(archivePath, callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe "when the second to last extension isn't .tar", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'invalid.txt.gz')
pathError = null
callback = (error, contents) -> pathError = error
archive.list(archivePath, callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe ".readFile()", ->
describe "when the path exists in the archive", ->
it "calls back with the contents of the given path", ->
archivePath = path.join(fixturesRoot, 'one-file.tar.gz')
pathContents = null
callback = (error, contents) -> pathContents = contents
archive.readFile(archivePath, 'file.txt', callback)
waitsFor -> pathContents?
runs -> expect(pathContents.toString()).toBe 'hello\n'
it "calls back with the contents of the given path", ->
archivePath = path.join(fixturesRoot, 'one-file.tgz')
pathContents = null
callback = (error, contents) -> pathContents = contents
archive.readFile(archivePath, 'file.txt', callback)
waitsFor -> pathContents?
runs -> expect(pathContents.toString()).toBe 'hello\n'
describe "when the path does not exist in the archive", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'one-file.tar.gz')
pathError = null
callback = (error, contents) -> pathError = error
archive.readFile(archivePath, 'not-a-file.txt', callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe "when the archive path does not exist", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'not-a-file.tar.gz')
pathError = null
callback = (error, contents) -> pathError = error
archive.readFile(archivePath, 'not-a-file.txt', callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe "when the archive path isn't a valid gzipped tar file", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'invalid.tar.gz')
pathError = null
callback = (error, contents) -> pathError = error
archive.readFile(archivePath, 'invalid.txt', callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe "when the second to last extension isn't .tar", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'invalid.txt.gz')
pathError = null
callback = (error, contents) -> pathError = error
archive.readFile(archivePath, 'invalid.txt', callback)
waitsFor -> pathError?
runs -> expect(pathError.message.length).toBeGreaterThan 0
describe ".readGzip()", ->
it "calls back with the string contents of the archive", ->
archivePath = path.join(fixturesRoot, 'file.txt.gz')
archiveContents = null
callback = (error, contents) -> archiveContents = contents
archive.readGzip(archivePath, callback)
waitsFor -> archiveContents?
runs -> expect(archiveContents.toString()).toBe 'hello\n'
describe "when the archive path isn't a valid gzipped tar file", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'invalid.tar.gz')
readError = null
callback = (error, contents) -> readError = error
archive.readGzip(archivePath, callback)
waitsFor -> readError?
runs -> expect(readError.message.length).toBeGreaterThan 0
describe "when the archive path does not exist", ->
it "calls back with an error", ->
archivePath = path.join(fixturesRoot, 'not-a-file.tar.gz')
readError = null
callback = (error, contents) -> readError = error
archive.readGzip(archivePath, callback)
waitsFor -> readError?
runs -> expect(readError.message.length).toBeGreaterThan 0