Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to kubernetes-client 1.0.0-rc6 #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions __tests__/k8s_lock_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ describe("K8SLock", () => {
readNamespacedLease: jest.fn(),
createNamespacedLease: jest.fn(() => {
return {
body: {
metadata: {
resourceVersion: 1231
},
spec: {

}
}
}
}),
patchNamespacedLease: jest.fn(),
Expand All @@ -28,15 +26,16 @@ describe("K8SLock", () => {
loadFromDefault: jest.fn(),
makeApiClient: jest.fn( () =>{
return mockApi;
})
}),
getCurrentCluster: jest.fn( () => { return { server:'localhost' } } )
}

k8s.KubeConfig.mockImplementation(() => mockKubeConfig);
k8s.CoordinationV1Api.mockImplementation(() => mockApi);
});

it("should create a new lock if it does not exist and createLeaseIfNotExist is true", async () => {
mockApi.readNamespacedLease.mockRejectedValue({ statusCode: 404 });
mockApi.readNamespacedLease.mockRejectedValue({ code: 404 });

const lock = new K8SLock({
leaseName: "test-lease",
Expand All @@ -49,7 +48,7 @@ describe("K8SLock", () => {
});

it("should not create a new lock if it does not exist and createLeaseIfNotExist is false", async () => {
mockApi.readNamespacedLease.mockRejectedValue({ statusCode: 404 });
mockApi.readNamespacedLease.mockRejectedValue({ code: 404 });

const lock = new K8SLock({
leaseName: "test-lease",
Expand All @@ -69,14 +68,12 @@ describe("K8SLock", () => {

it("should not overwrite lock if lock exists and is not expired", async () => {
mockApi.readNamespacedLease.mockResolvedValue({
body: {
metadata: {
resourceVersion: 1231
},
spec: {
renewTime: new Date(new Date().getTime() + 100000), // set to a future time
}
}
});

const lock = new K8SLock({
Expand All @@ -92,14 +89,12 @@ describe("K8SLock", () => {

it("should overwrite lock if lock exists and is expired", async () => {
mockApi.readNamespacedLease.mockResolvedValue({
body: {
metadata: {
resourceVersion: 12312
},
spec: {
renewTime: new Date(new Date().getTime() - 10000), // set to a past time
}
}
});

const lock = new K8SLock({
Expand All @@ -115,14 +110,12 @@ describe("K8SLock", () => {

it("should start locking if lock is acquired", async () => {
mockApi.readNamespacedLease.mockResolvedValue({
body: {
metadata: {
resourceVersion: 13112
},
spec: {
renewTime: new Date(new Date().getTime() - 10000), // set to a past time
}
}
});
mockApi.patchNamespacedLease.mockResolvedValue({});

Expand All @@ -141,14 +134,12 @@ describe("K8SLock", () => {
jest.useFakeTimers();

mockApi.readNamespacedLease.mockResolvedValue({
body: {
metadata: {
resourceVersion: 13112
},
spec: {
renewTime: new Date(new Date().getTime() - 10000), // set to a past time
}
}
});
mockApi.patchNamespacedLease.mockResolvedValue({});

Expand All @@ -175,25 +166,23 @@ describe("K8SLock", () => {
calls++;
if (calls === 1) {
return Promise.resolve({
body: {

metadata: {
resourceVersion: 13112
},
spec: {
renewTime: new Date(new Date().getTime() + 10000), // set to a past time
}
}

});
} else {
return Promise.resolve({
body: {
metadata: {
resourceVersion: 13112
},
spec: {
renewTime: new Date(new Date().getTime() - 10000), // set to a past time
}
}
});
}
});
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {K8SLock} = require("./k8s_lock");
const { K8SLock } = require("./k8s_lock");

module.exports = {
K8SLock
}
K8SLock,
};
Loading