Skip to content

Commit

Permalink
feat(api-gateway): add tests for /healtz, /readyz
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Dec 17, 2020
1 parent e3eccfb commit 371895d
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions packages/cubejs-api-gateway/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,32 @@ const compilerApi = jest.fn().mockImplementation(() => ({
},
}));

class DataSourceStorageMock {
async testConnections() {
return [];
}

async testOrchestratorConnections() {
return [];
}
}

const adapterApi = jest.fn().mockImplementation(() => ({
async executeQuery() {
return {
data: [{ foo__bar: 42 }],
};
},
testConnection: () => Promise.resolve(),
testOrchestratorConnections: () => Promise.resolve(),
executeQuery: async () => ({
data: [{ foo__bar: 42 }],
}),
}));

const logger = (type, message) => console.log({ type, ...message });

describe('API Gateway', () => {
process.env.NODE_ENV = 'production';
const apiGateway = new ApiGateway('secret', compilerApi, adapterApi, logger);
const apiGateway = new ApiGateway('secret', compilerApi, adapterApi, logger, {
standalone: true,
dataSourceStorage: new DataSourceStorageMock(),
});
process.env.NODE_ENV = null;
const app = express();
apiGateway.initApp(app);
Expand Down Expand Up @@ -225,5 +239,25 @@ describe('API Gateway', () => {
data: [{ 'Foo.bar': 42 }],
});
});

test('readyz', async () => {
const res = await request(app)
.get(`/readyz`)
.set('Content-type', 'application/json')
.set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M')
.expect(200);

expect(res.body).toMatchObject({ health: 'HEALTH' });
});

test('livez', async () => {
const res = await request(app)
.get(`/livez`)
.set('Content-type', 'application/json')
.set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M')
.expect(200);

expect(res.body).toMatchObject({ health: 'HEALTH' });
});
});
});

0 comments on commit 371895d

Please sign in to comment.