|
| 1 | +archive = require '../lib/ls-archive' |
| 2 | +path = require 'path' |
| 3 | + |
| 4 | +describe "bzipped tar files", -> |
| 5 | + fixturesRoot = null |
| 6 | + |
| 7 | + beforeEach -> |
| 8 | + fixturesRoot = path.join(__dirname, 'fixtures') |
| 9 | + |
| 10 | + describe ".list()", -> |
| 11 | + describe "when the archive file exists", -> |
| 12 | + it "returns files in the bzipped tar archive", -> |
| 13 | + bzipPaths = null |
| 14 | + callback = (error, paths) -> bzipPaths = paths |
| 15 | + archive.list(path.join(fixturesRoot, 'one-file.tar.bz2'), callback) |
| 16 | + waitsFor -> bzipPaths? |
| 17 | + runs -> |
| 18 | + expect(bzipPaths.length).toBe 1 |
| 19 | + expect(bzipPaths[0].path).toBe 'file.txt' |
| 20 | + expect(bzipPaths[0].isDirectory()).toBe false |
| 21 | + expect(bzipPaths[0].isFile()).toBe true |
| 22 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 23 | + |
| 24 | + it "returns files in the bzipped tar archive", -> |
| 25 | + bzipPaths = null |
| 26 | + callback = (error, paths) -> bzipPaths = paths |
| 27 | + archive.list(path.join(fixturesRoot, 'one-file.tbz'), callback) |
| 28 | + waitsFor -> bzipPaths? |
| 29 | + runs -> |
| 30 | + expect(bzipPaths.length).toBe 1 |
| 31 | + expect(bzipPaths[0].path).toBe 'file.txt' |
| 32 | + expect(bzipPaths[0].isDirectory()).toBe false |
| 33 | + expect(bzipPaths[0].isFile()).toBe true |
| 34 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 35 | + |
| 36 | + it "returns files in the bzipped tar archive", -> |
| 37 | + bzipPaths = null |
| 38 | + callback = (error, paths) -> bzipPaths = paths |
| 39 | + archive.list(path.join(fixturesRoot, 'one-file.tbz2'), callback) |
| 40 | + waitsFor -> bzipPaths? |
| 41 | + runs -> |
| 42 | + expect(bzipPaths.length).toBe 1 |
| 43 | + expect(bzipPaths[0].path).toBe 'file.txt' |
| 44 | + expect(bzipPaths[0].isDirectory()).toBe false |
| 45 | + expect(bzipPaths[0].isFile()).toBe true |
| 46 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 47 | + |
| 48 | + it "returns folders in the bzipped tar archive", -> |
| 49 | + bzipPaths = null |
| 50 | + callback = (error, paths) -> bzipPaths = paths |
| 51 | + archive.list(path.join(fixturesRoot, 'one-folder.tar.bz2'), callback) |
| 52 | + waitsFor -> bzipPaths? |
| 53 | + runs -> |
| 54 | + expect(bzipPaths.length).toBe 1 |
| 55 | + expect(bzipPaths[0].path).toBe 'folder' |
| 56 | + expect(bzipPaths[0].isDirectory()).toBe true |
| 57 | + expect(bzipPaths[0].isFile()).toBe false |
| 58 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 59 | + |
| 60 | + it "returns folders in the bzipped tar archive", -> |
| 61 | + bzipPaths = null |
| 62 | + callback = (error, paths) -> bzipPaths = paths |
| 63 | + archive.list(path.join(fixturesRoot, 'one-folder.tbz'), callback) |
| 64 | + waitsFor -> bzipPaths? |
| 65 | + runs -> |
| 66 | + expect(bzipPaths.length).toBe 1 |
| 67 | + expect(bzipPaths[0].path).toBe 'folder' |
| 68 | + expect(bzipPaths[0].isDirectory()).toBe true |
| 69 | + expect(bzipPaths[0].isFile()).toBe false |
| 70 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 71 | + |
| 72 | + it "returns folders in the bzipped tar archive", -> |
| 73 | + bzipPaths = null |
| 74 | + callback = (error, paths) -> bzipPaths = paths |
| 75 | + archive.list(path.join(fixturesRoot, 'one-folder.tbz2'), callback) |
| 76 | + waitsFor -> bzipPaths? |
| 77 | + runs -> |
| 78 | + expect(bzipPaths.length).toBe 1 |
| 79 | + expect(bzipPaths[0].path).toBe 'folder' |
| 80 | + expect(bzipPaths[0].isDirectory()).toBe true |
| 81 | + expect(bzipPaths[0].isFile()).toBe false |
| 82 | + expect(bzipPaths[0].isSymbolicLink()).toBe false |
| 83 | + |
| 84 | + describe "when the archive path does not exist", -> |
| 85 | + it "calls back with an error", -> |
| 86 | + archivePath = path.join(fixturesRoot, 'not-a-file.tar.bz2') |
| 87 | + pathError = null |
| 88 | + callback = (error) -> pathError = error |
| 89 | + archive.list(archivePath, callback) |
| 90 | + waitsFor -> pathError? |
| 91 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 92 | + |
| 93 | + describe "when the archive path isn't a valid bzipped tar file", -> |
| 94 | + it "calls back with an error", -> |
| 95 | + archivePath = path.join(fixturesRoot, 'invalid.tar.bz2') |
| 96 | + pathError = null |
| 97 | + callback = (error) -> pathError = error |
| 98 | + archive.list(archivePath, callback) |
| 99 | + waitsFor -> pathError? |
| 100 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 101 | + |
| 102 | + describe "when the second to last extension isn't .tar", -> |
| 103 | + it "calls back with an error", -> |
| 104 | + archivePath = path.join(fixturesRoot, 'invalid.txt.bz2') |
| 105 | + pathError = null |
| 106 | + callback = (error, contents) -> pathError = error |
| 107 | + archive.list(archivePath, callback) |
| 108 | + waitsFor -> pathError? |
| 109 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 110 | + |
| 111 | + describe ".readFile()", -> |
| 112 | + describe "when the path exists in the archive", -> |
| 113 | + it "calls back with the contents of the given path", -> |
| 114 | + archivePath = path.join(fixturesRoot, 'one-file.tar.bz2') |
| 115 | + pathContents = null |
| 116 | + callback = (error, contents) -> pathContents = contents |
| 117 | + archive.readFile(archivePath, 'file.txt', callback) |
| 118 | + waitsFor -> pathContents? |
| 119 | + runs -> expect(pathContents.toString()).toBe 'hello\n' |
| 120 | + |
| 121 | + it "calls back with the contents of the given path", -> |
| 122 | + archivePath = path.join(fixturesRoot, 'one-file.tbz') |
| 123 | + pathContents = null |
| 124 | + callback = (error, contents) -> pathContents = contents |
| 125 | + archive.readFile(archivePath, 'file.txt', callback) |
| 126 | + waitsFor -> pathContents? |
| 127 | + runs -> expect(pathContents.toString()).toBe 'hello\n' |
| 128 | + |
| 129 | + it "calls back with the contents of the given path", -> |
| 130 | + archivePath = path.join(fixturesRoot, 'one-file.tbz2') |
| 131 | + pathContents = null |
| 132 | + callback = (error, contents) -> pathContents = contents |
| 133 | + archive.readFile(archivePath, 'file.txt', callback) |
| 134 | + waitsFor -> pathContents? |
| 135 | + runs -> expect(pathContents.toString()).toBe 'hello\n' |
| 136 | + |
| 137 | + describe "when the path does not exist in the archive", -> |
| 138 | + it "calls back with an error", -> |
| 139 | + archivePath = path.join(fixturesRoot, 'one-file.tar.bz2') |
| 140 | + pathError = null |
| 141 | + callback = (error, contents) -> pathError = error |
| 142 | + archive.readFile(archivePath, 'not-a-file.txt', callback) |
| 143 | + waitsFor -> pathError? |
| 144 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 145 | + |
| 146 | + describe "when the archive path does not exist", -> |
| 147 | + it "calls back with an error", -> |
| 148 | + archivePath = path.join(fixturesRoot, 'not-a-file.tar.bz2') |
| 149 | + pathError = null |
| 150 | + callback = (error, contents) -> pathError = error |
| 151 | + archive.readFile(archivePath, 'not-a-file.txt', callback) |
| 152 | + waitsFor -> pathError? |
| 153 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 154 | + |
| 155 | + describe "when the archive path isn't a valid bzipped tar file", -> |
| 156 | + it "calls back with an error", -> |
| 157 | + archivePath = path.join(fixturesRoot, 'invalid.tar.bz2') |
| 158 | + pathError = null |
| 159 | + callback = (error, contents) -> pathError = error |
| 160 | + archive.readFile(archivePath, 'invalid.txt', callback) |
| 161 | + waitsFor -> pathError? |
| 162 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 163 | + |
| 164 | + describe "when the second to last extension isn't .tar", -> |
| 165 | + it "calls back with an error", -> |
| 166 | + archivePath = path.join(fixturesRoot, 'invalid.txt.bz2') |
| 167 | + pathError = null |
| 168 | + callback = (error, contents) -> pathError = error |
| 169 | + archive.readFile(archivePath, 'invalid.txt', callback) |
| 170 | + waitsFor -> pathError? |
| 171 | + runs -> expect(pathError.message.length).toBeGreaterThan 0 |
| 172 | + |
| 173 | + describe ".readBzip()", -> |
| 174 | + it "calls back with the string contents of the archive", -> |
| 175 | + archivePath = path.join(fixturesRoot, 'file.txt.bz2') |
| 176 | + archiveContents = null |
| 177 | + callback = (error, contents) -> archiveContents = contents |
| 178 | + archive.readBzip(archivePath, callback) |
| 179 | + waitsFor -> archiveContents? |
| 180 | + runs -> expect(archiveContents.toString()).toBe 'hello\n' |
| 181 | + |
| 182 | + describe "when the archive path isn't a valid bzipped tar file", -> |
| 183 | + it "calls back with an error", -> |
| 184 | + archivePath = path.join(fixturesRoot, 'invalid.tar.bz2') |
| 185 | + readError = null |
| 186 | + callback = (error, contents) -> readError = error |
| 187 | + archive.readBzip(archivePath, callback) |
| 188 | + waitsFor -> readError? |
| 189 | + runs -> expect(readError.message.length).toBeGreaterThan 0 |
| 190 | + |
| 191 | + describe "when the archive path does not exist", -> |
| 192 | + it "calls back with an error", -> |
| 193 | + archivePath = path.join(fixturesRoot, 'not-a-file.tar.bz2') |
| 194 | + readError = null |
| 195 | + callback = (error, contents) -> readError = error |
| 196 | + archive.readBzip(archivePath, callback) |
| 197 | + waitsFor -> readError? |
| 198 | + runs -> expect(readError.message.length).toBeGreaterThan 0 |
0 commit comments