-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathremoteSource.spec.ts
More file actions
89 lines (76 loc) · 3.17 KB
/
remoteSource.spec.ts
File metadata and controls
89 lines (76 loc) · 3.17 KB
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
import { expect } from "chai";
import * as sinon from "sinon";
import * as fs from "fs";
import * as remoteSourceModule from "./remoteSource";
import { cloneRemoteSource, GitClient } from "./remoteSource";
import { FirebaseError } from "../../error";
describe("remoteSource", () => {
describe("cloneRemoteSource", () => {
let existsSyncStub: sinon.SinonStub;
let isGitAvailableStub: sinon.SinonStub;
let cloneStub: sinon.SinonStub;
let fetchStub: sinon.SinonStub;
let checkoutStub: sinon.SinonStub;
let initSparseStub: sinon.SinonStub;
let setSparseStub: sinon.SinonStub;
let mockGitClient: GitClient;
beforeEach(() => {
existsSyncStub = sinon.stub(fs, "existsSync");
isGitAvailableStub = sinon.stub(remoteSourceModule, "isGitAvailable");
cloneStub = sinon.stub().returns({ status: 0 });
fetchStub = sinon.stub().returns({ status: 0 });
checkoutStub = sinon.stub().returns({ status: 0 });
initSparseStub = sinon.stub().returns({ status: 0 });
setSparseStub = sinon.stub().returns({ status: 0 });
mockGitClient = {
clone: cloneStub,
fetch: fetchStub,
checkout: checkoutStub,
initSparseCheckout: initSparseStub,
setSparsePaths: setSparseStub,
} as unknown as GitClient;
});
afterEach(() => {
existsSyncStub.restore();
isGitAvailableStub.restore();
});
it("should handle clone failures with meaningful errors", async () => {
isGitAvailableStub.returns(true);
cloneStub.returns({
status: 1,
stderr: "fatal: unable to access 'https://github.com/org/repo': Could not resolve host",
});
await expect(
cloneRemoteSource("https://github.com/org/repo", "main", undefined, mockGitClient),
).to.be.rejectedWith(FirebaseError, /Unable to access repository/);
});
it("should handle fetch failures for invalid refs", async () => {
isGitAvailableStub.returns(true);
fetchStub.returns({
status: 1,
stderr: "error: pathspec 'bad-ref' did not match any file(s) known to git",
});
await expect(
cloneRemoteSource("https://github.com/org/repo", "bad-ref", undefined, mockGitClient),
).to.be.rejectedWith(FirebaseError, /Git ref 'bad-ref' not found/);
});
it("should validate subdirectory exists after clone", async () => {
isGitAvailableStub.returns(true);
setSparseStub.returns({
status: 1,
stderr: "fatal: pathspec 'subdir' did not match any files",
});
await expect(
cloneRemoteSource("https://github.com/org/repo", "main", "subdir", mockGitClient),
).to.be.rejectedWith(FirebaseError, /Directory 'subdir' not found/);
});
it("should validate functions.yaml exists", async () => {
isGitAvailableStub.returns(true);
existsSyncStub.withArgs(sinon.match(/firebase-functions-remote/)).returns(true);
existsSyncStub.withArgs(sinon.match(/functions\.yaml$/)).returns(false);
await expect(
cloneRemoteSource("https://github.com/org/repo", "main", undefined, mockGitClient),
).to.be.rejectedWith(FirebaseError, /missing a required deployment manifest/);
});
});
});