-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-5141: Fix commit check for prod deploy (#228)
- Loading branch information
Showing
6 changed files
with
101 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/deploy-utils/src/utils/git/get-current-deployed-commit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Stream from "stream"; | ||
import { tagIsValid } from "."; | ||
|
||
describe("getCurrentDeployedCommit without mocking https requests", () => { | ||
it("fetches the commit from spruce", async () => { | ||
const { getCurrentlyDeployedCommit } = await import( | ||
"./get-current-deployed-commit" | ||
); | ||
expect(await getCurrentlyDeployedCommit("spruce")).toHaveLength(40); | ||
}); | ||
|
||
it("fetches the commit from parsley", async () => { | ||
const { getCurrentlyDeployedCommit } = await import( | ||
"./get-current-deployed-commit" | ||
); | ||
expect(await getCurrentlyDeployedCommit("parsley")).toHaveLength(40); | ||
}); | ||
}); | ||
|
||
describe("when get request fails", () => { | ||
beforeEach(() => { | ||
vi.resetModules(); | ||
vi.doMock("https", () => ({ | ||
default: vi.fn(), | ||
get: vi.fn().mockImplementation((_, cb) => { | ||
const s = new Stream(); | ||
cb(s); | ||
s.emit("error", new Error("invalid")); | ||
}), | ||
})); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
vi.doUnmock("https"); | ||
}); | ||
|
||
it("gets a local spruce tag", async () => { | ||
const { getCurrentlyDeployedCommit } = await import( | ||
"./get-current-deployed-commit" | ||
); | ||
const app = "spruce"; | ||
const commit = await getCurrentlyDeployedCommit(app); | ||
expect(commit).not.toHaveLength(40); | ||
expect(tagIsValid(app, commit)).toBe(true); | ||
}); | ||
|
||
it("gets a local parsley tag", async () => { | ||
const { getCurrentlyDeployedCommit } = await import( | ||
"./get-current-deployed-commit" | ||
); | ||
const app = "parsley"; | ||
const commit = await getCurrentlyDeployedCommit(app); | ||
expect(commit).not.toHaveLength(40); | ||
expect(tagIsValid(app, commit)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
import { getLatestTag } from "."; | ||
import { DeployableApp } from "../types"; | ||
import { getLatestTag, tagIsValid } from "."; | ||
|
||
describe("getLatestTag", () => { | ||
const currentlyDeployedTagRegex = (app: DeployableApp) => | ||
new RegExp(`${app}/v\\d+.\\d+.\\d+`); | ||
|
||
it("currentlyDeployedTagRegex should match on a known valid tag", () => { | ||
const tag = currentlyDeployedTagRegex("parsley").test("parsley/v1.2.3"); | ||
expect(tag).toBeTruthy(); | ||
describe("tagIsValid", () => { | ||
it("should match on a known valid tag", () => { | ||
expect(tagIsValid("parsley", "parsley/v1.2.3")).toEqual(true); | ||
}); | ||
|
||
it("currentlyDeployedTagRegex should not match on the wrong app's tag tag", () => { | ||
const tag = currentlyDeployedTagRegex("parsley").test("spruce/v1.2.3"); | ||
expect(tag).toBeFalsy(); | ||
it("should not match on the wrong app's tag", () => { | ||
expect(tagIsValid("parsley", "spruce/v1.2.3")).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe("getLatestTag", () => { | ||
it("should return the latest spruce tag", () => { | ||
const app = "spruce"; | ||
const latestTag = getLatestTag(app); | ||
const latestTagIsTag = currentlyDeployedTagRegex(app).test(latestTag); | ||
expect(latestTagIsTag).toBeTruthy(); | ||
expect(tagIsValid(app, latestTag)).toEqual(true); | ||
}); | ||
|
||
it("should return the latest parsley tag", () => { | ||
const app = "parsley"; | ||
const latestTag = getLatestTag(app); | ||
const latestTagIsTag = currentlyDeployedTagRegex(app).test(latestTag); | ||
expect(latestTagIsTag).toBeTruthy(); | ||
expect(tagIsValid(app, latestTag)).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters