-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating upload mechanism to split functionality
- Loading branch information
Showing
13 changed files
with
97 additions
and
100 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
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 @@ | ||
require("dotenv").config({ path: ".env.test" }); |
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,66 +1,70 @@ | ||
// import { LightBlockUpload } from './index'; | ||
// import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3"; | ||
// import { LightBlockCache } from "../cache"; | ||
// import { LightBlock } from "../models/lightstreamer"; | ||
import { LightBlockUpload } from "./index"; | ||
import { | ||
S3Client, | ||
PutObjectCommand, | ||
ListObjectsV2Command, | ||
} from "@aws-sdk/client-s3"; | ||
import { LightBlockCache } from "../cache"; | ||
import { LightBlock } from "../models/lightstreamer"; | ||
|
||
// jest.mock("@aws-sdk/client-s3", () => { | ||
// return { | ||
// S3Client: jest.fn().mockImplementation(() => { | ||
// return { | ||
// send: jest.fn() | ||
// }; | ||
// }) | ||
// }; | ||
// }); | ||
// jest.mock("../cache"); | ||
// jest.mock("../models/lightstreamer"); | ||
jest.mock("@aws-sdk/client-s3", () => { | ||
return { | ||
S3Client: jest.fn().mockImplementation(() => { | ||
return { | ||
send: jest.fn().mockImplementation(() => { | ||
return { Contents: [] }; | ||
}), | ||
}; | ||
}), | ||
ListObjectsV2Command: jest.fn().mockImplementation(() => { | ||
return {}; | ||
}), | ||
PutObjectCommand: jest.fn().mockImplementation(() => { | ||
return {}; | ||
}), | ||
}; | ||
}); | ||
|
||
// describe('LightBlockUpload', () => { | ||
// let lightBlockUpload: LightBlockUpload; | ||
// let mockCache: jest.Mocked<LightBlockCache>; | ||
// let mockS3Client: jest.Mocked<S3Client>; | ||
describe("LightBlockUpload", () => { | ||
let lightBlockUpload: LightBlockUpload; | ||
let mockCache: jest.Mocked<LightBlockCache>; | ||
let mockS3Client: jest.Mocked<S3Client>; | ||
|
||
// beforeAll(() => { | ||
// process.env["BUCKET_ENDPOINT"] = 'test-endpoint'; | ||
// process.env["BUCKET_ACCESS_KEY_ID"] = 'test-access-key-id'; | ||
// process.env["BUCKET_SECRET_ACCESS_KEY"] = 'test-secret-access-key'; | ||
// process.env["BUCKET_NAME"] = 'test-bucket-name'; | ||
beforeAll(() => { | ||
mockCache = new LightBlockCache() as jest.Mocked<LightBlockCache>; | ||
mockS3Client = new S3Client({}) as jest.Mocked<S3Client>; | ||
lightBlockUpload = new LightBlockUpload(mockCache); | ||
}); | ||
|
||
// mockCache = new LightBlockCache() as jest.Mocked<LightBlockCache>; | ||
// mockS3Client = new S3Client({}) as jest.Mocked<S3Client>; | ||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
// lightBlockUpload = new LightBlockUpload(mockCache); | ||
// }); | ||
it("should throw an error if environment variables are not set", () => { | ||
delete process.env["BUCKET_ENDPOINT"]; | ||
expect(() => new LightBlockUpload(mockCache)).toThrow(); | ||
}); | ||
|
||
// afterAll(() => { | ||
// jest.resetAllMocks(); | ||
// }); | ||
it("should upload blocks", async () => { | ||
const mockBlock = LightBlock.fromJSON({ | ||
sequence: 1000, | ||
hash: "test-hash", | ||
previousBlockHash: "test-previous-hash", | ||
timestamp: 123456789, | ||
transactions: [], | ||
noteSize: 0, | ||
}); | ||
mockCache.getBlockBySequence.mockResolvedValue(mockBlock); | ||
mockCache.getHeadSequence.mockResolvedValue(1001); | ||
mockCache.getUploadHead.mockResolvedValue(0); | ||
|
||
// it('should throw an error if environment variables are not set', () => { | ||
// delete process.env["BUCKET_ENDPOINT"]; | ||
// expect(() => new LightBlockUpload(mockCache)).toThrow('BUCKET_ENDPOINT not set'); | ||
// }); | ||
const mockSend = jest.fn(); | ||
mockS3Client.send = mockSend; | ||
|
||
// it('should upload blocks', async () => { | ||
// const mockBlock = LightBlock.fromJSON({ | ||
// sequence: 1000, | ||
// hash: 'test-hash', | ||
// previousBlockHash: 'test-previous-hash', | ||
// timestamp: 123456789, | ||
// transactions: [], | ||
// noteSize: 0 | ||
// }); | ||
// mockCache.getBlockBySequence.mockResolvedValue(mockBlock); | ||
// mockCache.getHeadSequence.mockResolvedValue(1001); | ||
// mockCache.getUploadHead.mockResolvedValue(0); | ||
await lightBlockUpload.watchAndUpload(); | ||
|
||
// const mockSend = jest.fn(); | ||
// mockS3Client.send = mockSend; | ||
|
||
// await lightBlockUpload.watchAndUpload(); | ||
|
||
// expect(mockSend).toHaveBeenCalledWith(expect.any(ListObjectsV2Command)); | ||
// expect(mockSend).toHaveBeenCalledWith(expect.any(PutObjectCommand)); | ||
// expect(mockCache.putUploadHead).toHaveBeenCalledWith('test-hash'); | ||
// }); | ||
// }); | ||
expect(mockSend).toHaveBeenCalledWith(expect.any(ListObjectsV2Command)); | ||
expect(mockSend).toHaveBeenCalledWith(expect.any(PutObjectCommand)); | ||
expect(mockCache.putUploadHead).toHaveBeenCalledWith("test-hash"); | ||
}); | ||
}); |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 +1 @@ | ||
MANIFEST-000122 | ||
MANIFEST-000231 |
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,3 +0,0 @@ | ||
2024/03/19-09:37:17.297631 173e2b000 Recovering log #121 | ||
2024/03/19-09:37:17.298491 173e2b000 Delete type=3 #119 | ||
2024/03/19-09:37:17.298537 173e2b000 Delete type=0 #121 | ||
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,5 +1,3 @@ | ||
2024/03/19-09:37:16.985331 172e13000 Recovering log #118 | ||
2024/03/19-09:37:16.985449 172e13000 Level-0 table #120: started | ||
2024/03/19-09:37:16.985657 172e13000 Level-0 table #120: 1766 bytes OK | ||
2024/03/19-09:37:16.986076 172e13000 Delete type=3 #117 | ||
2024/03/19-09:37:16.986118 172e13000 Delete type=0 #118 | ||
2024/03/20-17:13:07.794174 171fcb000 Recovering log #230 | ||
2024/03/20-17:13:07.795044 171fcb000 Delete type=3 #229 | ||
2024/03/20-17:13:07.795090 171fcb000 Delete type=0 #230 |
Binary file not shown.