mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-19 03:06:27 +00:00
Merge pull request #1415 from balena-io/1299
Fixing v1 start/stop endpoint issue with service access
This commit is contained in:
commit
eff8d91105
@ -28,7 +28,7 @@ export const createV1Api = function (router, applications) {
|
||||
return applications
|
||||
.getCurrentApp(appId)
|
||||
.then(function (app) {
|
||||
let service = app?.app.services?.[0];
|
||||
let service = app?.services?.[0];
|
||||
if (service == null) {
|
||||
return res.status(400).send('App not found');
|
||||
}
|
||||
|
@ -95,7 +95,6 @@ describe('SupervisorAPI', () => {
|
||||
await request
|
||||
.get('/v1/healthy')
|
||||
.set('Accept', 'application/json')
|
||||
.set('Authorization', `Bearer ${VALID_SECRET}`)
|
||||
.expect(sampleResponses.V1.GET['/healthy [2]'].statusCode)
|
||||
.then((response) => {
|
||||
expect(response.body).to.deep.equal(
|
||||
@ -107,7 +106,40 @@ describe('SupervisorAPI', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: add tests for V1 endpoints
|
||||
describe('GET /v1/apps/:appId', () => {
|
||||
it('returns information about a SPECIFIC application', async () => {
|
||||
await request
|
||||
.get('/v1/apps/2')
|
||||
.set('Accept', 'application/json')
|
||||
.set('Authorization', `Bearer ${VALID_SECRET}`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(sampleResponses.V1.GET['/apps/2'].statusCode)
|
||||
.then((response) => {
|
||||
expect(response.body).to.deep.equal(
|
||||
sampleResponses.V1.GET['/apps/2'].body,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /v1/apps/:appId/stop', () => {
|
||||
it('stops a SPECIFIC application and returns a containerId', async () => {
|
||||
await request
|
||||
.post('/v1/apps/2/stop')
|
||||
.set('Accept', 'application/json')
|
||||
.set('Authorization', `Bearer ${VALID_SECRET}`)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(sampleResponses.V1.GET['/apps/2/stop'].statusCode)
|
||||
.then((response) => {
|
||||
expect(response.body).to.deep.equal(
|
||||
sampleResponses.V1.GET['/apps/2/stop'].body,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /v1/device', () => {
|
||||
it('returns MAC address', async () => {
|
||||
const response = await request
|
||||
|
@ -10,6 +10,22 @@
|
||||
"statusCode": 500,
|
||||
"body": {},
|
||||
"text": "Unhealthy"
|
||||
},
|
||||
"/apps/2": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"appId": 2,
|
||||
"containerId": "abc123",
|
||||
"commit": "7fc9c5bea8e361acd49886fe6cc1e1cd",
|
||||
"env": {},
|
||||
"releaseId": 77777
|
||||
}
|
||||
},
|
||||
"/apps/2/stop": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"containerId": "abc123"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1,3 +1,4 @@
|
||||
import * as _ from 'lodash';
|
||||
import { Router } from 'express';
|
||||
import { fs } from 'mz';
|
||||
|
||||
@ -40,6 +41,7 @@ const STUBBED_VALUES = {
|
||||
{
|
||||
appId: 2,
|
||||
imageId: 3333,
|
||||
containerId: 'abc123',
|
||||
status: 'Running',
|
||||
releaseId: 77777,
|
||||
createdAt: new Date('2020-05-15T19:33:06.088Z'),
|
||||
@ -140,7 +142,9 @@ function buildRoutes(appManager: ApplicationManager): Router {
|
||||
|
||||
const originalNetGetAll = networkManager.getAllByAppId;
|
||||
const originalVolGetAll = volumeManager.getAllByAppId;
|
||||
const originalSvcGetAppId = serviceManager.getAllByAppId;
|
||||
const originalSvcGetStatus = serviceManager.getStatus;
|
||||
|
||||
function setupStubs() {
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
networkManager.getAllByAppId = async () => STUBBED_VALUES.networks;
|
||||
@ -148,6 +152,9 @@ function setupStubs() {
|
||||
volumeManager.getAllByAppId = async () => STUBBED_VALUES.volumes;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getStatus = async () => STUBBED_VALUES.services;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getAllByAppId = async (appId) =>
|
||||
_.filter(STUBBED_VALUES.services, (service) => service.appId === appId);
|
||||
}
|
||||
|
||||
function restoreStubs() {
|
||||
@ -157,6 +164,8 @@ function restoreStubs() {
|
||||
volumeManager.getAllByAppId = originalVolGetAll;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getStatus = originalSvcGetStatus;
|
||||
// @ts-expect-error Assigning to a RO property
|
||||
serviceManager.getAllByAppId = originalSvcGetAppId;
|
||||
}
|
||||
|
||||
interface SupervisorAPIOpts {
|
||||
|
Loading…
Reference in New Issue
Block a user