forked from docker/build-push-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: start sending get request with query params
We are incorrectly using formData in a get request. To move away from this we send both query params and formData until the server is fully upgraded. After which we can stop sending formData.
- Loading branch information
1 parent
0186286
commit 0f99a0b
Showing
8 changed files
with
131 additions
and
58 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as reporter from '../reporter'; | ||
import { getStickyDisk } from '../setup_builder'; | ||
import FormData from 'form-data'; | ||
|
||
jest.mock('../reporter'); | ||
|
||
describe('getStickyDisk', () => { | ||
const mockGet = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
process.env.GITHUB_REPO_NAME = 'test-repo'; | ||
process.env.BLACKSMITH_REGION = 'test-region'; | ||
process.env.BLACKSMITH_INSTALLATION_MODEL_ID = 'test-model'; | ||
process.env.VM_ID = 'test-vm'; | ||
|
||
(reporter.createBlacksmithAgentClient as jest.Mock).mockResolvedValue({}); | ||
(reporter.get as jest.Mock).mockImplementation(mockGet); | ||
mockGet.mockResolvedValue({ | ||
data: { | ||
expose_id: 'test-expose-id', | ||
disk_identifier: 'test-device' | ||
} | ||
}); | ||
}); | ||
|
||
it('sets both FormData and query parameters correctly', async () => { | ||
const appendSpy = jest.spyOn(FormData.prototype, 'append'); | ||
|
||
await getStickyDisk(); | ||
|
||
expect(mockGet).toHaveBeenCalledTimes(1); | ||
const [, url, formData] = mockGet.mock.calls[0]; | ||
|
||
// Verify query parameters | ||
expect(url).toContain('stickyDiskKey=test-repo'); | ||
expect(url).toContain('region=test-region'); | ||
expect(url).toContain('installationModelID=test-model'); | ||
expect(url).toContain('vmID=test-vm'); | ||
|
||
// Verify FormData is correct type | ||
expect(formData instanceof FormData).toBeTruthy(); | ||
|
||
// Verify the headers are set correctly | ||
const headers = formData.getHeaders(); | ||
expect(headers['content-type']).toContain('multipart/form-data'); | ||
|
||
// Verify the correct fields were appended | ||
expect(appendSpy).toHaveBeenCalledWith('stickyDiskKey', 'test-repo'); | ||
expect(appendSpy).toHaveBeenCalledWith('region', 'test-region'); | ||
expect(appendSpy).toHaveBeenCalledWith('installationModelID', 'test-model'); | ||
expect(appendSpy).toHaveBeenCalledWith('vmID', 'test-vm'); | ||
}); | ||
}); |
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