1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

chore(project): add prettier for code format (#3645)

* chore(project): install prettier and lint-staged

* chore(project): apply prettier to html too

* chore(project): git ignore eslintcache

* chore(project): add a comment about format script

* chore(prettier): update printWidth

* chore(prettier): remove useTabs option

* chore(prettier): add HTML validation

* refactor(prettier): fix closing tags

* feat(prettier): define angular parser for html templates

* style(prettier): run prettier on codebase

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
Chaim Lev-Ari 2020-04-11 00:54:53 +03:00 committed by GitHub
parent 6663073be1
commit cf5056d9c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
714 changed files with 31228 additions and 28305 deletions

View file

@ -1,57 +1,53 @@
describe('ContainerController', function () {
var $scope, $httpBackend, mockContainer, $routeParams;
var $scope, $httpBackend, mockContainer, $routeParams;
beforeEach(module('portainer'));
beforeEach(module('portainer'));
beforeEach(inject(function ($rootScope, $controller, _$routeParams_) {
$scope = $rootScope.$new();
$routeParams = _$routeParams_;
$controller('ContainerController', {
$scope: $scope
});
angular.mock.inject(function (_$httpBackend_, _Container_) {
mockContainer = _Container_;
$httpBackend = _$httpBackend_;
});
}));
function expectGetContainer() {
$httpBackend.expectGET('dockerapi/containers/json').respond({
'Created': 1421817232,
'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
'Image': 'portainer:latest',
'Name': '/portainer'
});
}
it("a correct rename request to the Docker remote API", function () {
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$scope.container = {
'Created': 1421817232,
'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
'Image': 'portainer:latest',
'Name': '/portainer'
};
$scope.container.newContainerName = "newName";
var newContainerName = "newName";
expectGetContainer();
$httpBackend.expectGET('dockerapi/containers/changes').respond([{"Kind": 1, "Path": "/docker.sock"}]);
$httpBackend.expectPOST('dockerapi/containers/' + $routeParams.id + '/rename?name=newName').
respond({
'name': newContainerName
});
$scope.renameContainer();
$httpBackend.flush();
expect($scope.container.Name).toBe(newContainerName);
expect($scope.container.edit).toBeFalsy();
beforeEach(inject(function ($rootScope, $controller, _$routeParams_) {
$scope = $rootScope.$new();
$routeParams = _$routeParams_;
$controller('ContainerController', {
$scope: $scope,
});
});
angular.mock.inject(function (_$httpBackend_, _Container_) {
mockContainer = _Container_;
$httpBackend = _$httpBackend_;
});
}));
function expectGetContainer() {
$httpBackend.expectGET('dockerapi/containers/json').respond({
Created: 1421817232,
id: 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
Image: 'portainer:latest',
Name: '/portainer',
});
}
it('a correct rename request to the Docker remote API', function () {
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$scope.container = {
Created: 1421817232,
id: 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
Image: 'portainer:latest',
Name: '/portainer',
};
$scope.container.newContainerName = 'newName';
var newContainerName = 'newName';
expectGetContainer();
$httpBackend.expectGET('dockerapi/containers/changes').respond([{ Kind: 1, Path: '/docker.sock' }]);
$httpBackend.expectPOST('dockerapi/containers/' + $routeParams.id + '/rename?name=newName').respond({
name: newContainerName,
});
$scope.renameContainer();
$httpBackend.flush();
expect($scope.container.Name).toBe(newContainerName);
expect($scope.container.edit).toBeFalsy();
});
});

View file

@ -1,33 +1,33 @@
describe("ContainerTopController", function () {
var $scope, $httpBackend, $routeParams;
describe('ContainerTopController', function () {
var $scope, $httpBackend, $routeParams;
beforeEach(angular.mock.module('portainer'));
beforeEach(angular.mock.module('portainer'));
beforeEach(inject(function (_$rootScope_, _$httpBackend_, $controller, _$routeParams_) {
$scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$controller('ContainerTopController', {
'$scope': $scope,
'$routeParams': $routeParams
});
}));
it("should test controller initialize", function () {
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/json').respond(200, {Name: '/foo'});
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/top?ps_args=').respond(200);
expect($scope.ps_args).toBeDefined();
$httpBackend.flush();
beforeEach(inject(function (_$rootScope_, _$httpBackend_, $controller, _$routeParams_) {
$scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$controller('ContainerTopController', {
$scope: $scope,
$routeParams: $routeParams,
});
}));
it("a correct top request to the Docker remote API", function () {
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/json').respond(200, {Name: '/foo'});
$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=').respond(200);
$routeParams.id = '123456789123456789123456789';
$scope.ps_args = 'aux';
$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=' + $scope.ps_args).respond(200);
$scope.getTop();
$httpBackend.flush();
});
});
it('should test controller initialize', function () {
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/json').respond(200, { Name: '/foo' });
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/top?ps_args=').respond(200);
expect($scope.ps_args).toBeDefined();
$httpBackend.flush();
});
it('a correct top request to the Docker remote API', function () {
$httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/json').respond(200, { Name: '/foo' });
$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=').respond(200);
$routeParams.id = '123456789123456789123456789';
$scope.ps_args = 'aux';
$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=' + $scope.ps_args).respond(200);
$scope.getTop();
$httpBackend.flush();
});
});

View file

@ -1,83 +1,85 @@
describe('NetworkController', function () {
var $scope, $httpBackend, $routeParams;
var $scope, $httpBackend, $routeParams;
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b';
$controller('NetworkController', {
'$scope': $scope,
'$routeParams': $routeParams
});
}));
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b';
$controller('NetworkController', {
$scope: $scope,
$routeParams: $routeParams,
});
}));
it('initializes correctly', function () {
expectGetNetwork();
$httpBackend.flush();
});
it('initializes correctly', function () {
expectGetNetwork();
$httpBackend.flush();
});
it('issues a correct connect call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectPOST('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b/connect', {'Container': 'containerId'}).respond(200);
$scope.connect($routeParams.id, 'containerId');
$httpBackend.flush();
});
it('issues a correct disconnect call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectPOST('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b/disconnect', {'Container': 'containerId'}).respond(200);
$scope.disconnect($routeParams.id, 'containerId');
$httpBackend.flush();
});
it('issues a correct remove call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectDELETE('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b').respond(204);
$scope.remove($routeParams.id);
$httpBackend.flush();
});
it('issues a correct connect call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectPOST('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b/connect', { Container: 'containerId' }).respond(200);
$scope.connect($routeParams.id, 'containerId');
$httpBackend.flush();
});
it('issues a correct disconnect call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectPOST('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b/disconnect', { Container: 'containerId' }).respond(200);
$scope.disconnect($routeParams.id, 'containerId');
$httpBackend.flush();
});
it('issues a correct remove call to the remote API', function () {
expectGetNetwork();
$httpBackend.expectDELETE('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b').respond(204);
$scope.remove($routeParams.id);
$httpBackend.flush();
});
function expectGetNetwork() {
$httpBackend.expectGET('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b').respond({
"Name": "bridge",
"Id": "f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b",
"Scope": "local",
"Driver": "bridge",
"IPAM": {
"Driver": "default",
"Config": [{
"Subnet": "172.17.0.1/16",
"Gateway": "172.17.0.1"
}]
},
"Containers": {
"727fe76cd0bd65033baab3045508784a166fbc67d177e91c1874b6b29eae946a": {
"EndpointID": "c17ec80e2cfc8eaedc7737b7bb6f954adff439767197ef89c4a5b4127d07b267",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"8c32c2446c3dfe0defac2dc8b5fd927cd394f15e08051c677a681bf36877175b": {
"EndpointID": "cf7e795c978ab194d1af4a3efdc177d84c075582ba30a7cff414c7d516236af1",
"MacAddress": "02:42:ac:11:00:04",
"IPv4Address": "172.17.0.4/16",
"IPv6Address": ""
},
"cfe81fc97b1f857fdb3061fe487a064b8b57d8f112910954ac16910400d2e058": {
"EndpointID": "611929ffcff2ced1db8e88f77e009c4fb4a4736395251cd97553b242e2e23bf1",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
}
});
}
});
function expectGetNetwork() {
$httpBackend.expectGET('dockerapi/networks/f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b').respond({
Name: 'bridge',
Id: 'f1e1ce1613ccd374a75caf5e2c3ab35520d1944f91498c1974ec86fb4019c79b',
Scope: 'local',
Driver: 'bridge',
IPAM: {
Driver: 'default',
Config: [
{
Subnet: '172.17.0.1/16',
Gateway: '172.17.0.1',
},
],
},
Containers: {
'727fe76cd0bd65033baab3045508784a166fbc67d177e91c1874b6b29eae946a': {
EndpointID: 'c17ec80e2cfc8eaedc7737b7bb6f954adff439767197ef89c4a5b4127d07b267',
MacAddress: '02:42:ac:11:00:03',
IPv4Address: '172.17.0.3/16',
IPv6Address: '',
},
'8c32c2446c3dfe0defac2dc8b5fd927cd394f15e08051c677a681bf36877175b': {
EndpointID: 'cf7e795c978ab194d1af4a3efdc177d84c075582ba30a7cff414c7d516236af1',
MacAddress: '02:42:ac:11:00:04',
IPv4Address: '172.17.0.4/16',
IPv6Address: '',
},
cfe81fc97b1f857fdb3061fe487a064b8b57d8f112910954ac16910400d2e058: {
EndpointID: '611929ffcff2ced1db8e88f77e009c4fb4a4736395251cd97553b242e2e23bf1',
MacAddress: '02:42:ac:11:00:02',
IPv4Address: '172.17.0.2/16',
IPv6Address: '',
},
},
Options: {
'com.docker.network.bridge.default_bridge': 'true',
'com.docker.network.bridge.enable_icc': 'true',
'com.docker.network.bridge.enable_ip_masquerade': 'true',
'com.docker.network.bridge.host_binding_ipv4': '0.0.0.0',
'com.docker.network.bridge.name': 'docker0',
'com.docker.network.driver.mtu': '1500',
},
});
}
});

View file

@ -1,107 +1,109 @@
describe('NetworksController', function () {
var $scope, $httpBackend, $routeParams;
var $scope, $httpBackend, $routeParams;
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$controller('NetworksController', {
'$scope': $scope,
'$routeParams': $routeParams
});
}));
it('initializes correctly', function () {
expectGetNetwork();
$httpBackend.flush();
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$controller('NetworksController', {
$scope: $scope,
$routeParams: $routeParams,
});
}));
it('initializes correctly', function () {
expectGetNetwork();
$httpBackend.flush();
});
it('issues correct remove calls to the remote API', function () {
expectGetNetwork();
$httpBackend.flush();
$scope.networks[0].Checked = true;
$scope.networks[2].Checked = true;
$httpBackend.expectDELETE('dockerapi/networks/f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566').respond(204);
$httpBackend.expectDELETE('dockerapi/networks/13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e').respond(204);
$scope.removeAction();
$httpBackend.flush();
});
it('issues a correct network creation call to the remote API', function () {
expectGetNetwork();
var createBody = {
"Name":"isolated_nw",
"Driver":"bridge",
"IPAM":{
"Config":[{
"Subnet":"172.20.0.0/16",
"IPRange":"172.20.10.0/24",
"Gateway":"172.20.10.11"
}]
}};
$httpBackend.expectPOST('dockerapi/networks/create', createBody).respond(201);
expectGetNetwork();
$scope.addNetwork(createBody);
$httpBackend.flush();
});
it('issues correct remove calls to the remote API', function () {
expectGetNetwork();
$httpBackend.flush();
$scope.networks[0].Checked = true;
$scope.networks[2].Checked = true;
$httpBackend.expectDELETE('dockerapi/networks/f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566').respond(204);
$httpBackend.expectDELETE('dockerapi/networks/13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e').respond(204);
$scope.removeAction();
$httpBackend.flush();
});
it('issues a correct network creation call to the remote API', function () {
expectGetNetwork();
var createBody = {
Name: 'isolated_nw',
Driver: 'bridge',
IPAM: {
Config: [
{
Subnet: '172.20.0.0/16',
IPRange: '172.20.10.0/24',
Gateway: '172.20.10.11',
},
],
},
};
$httpBackend.expectPOST('dockerapi/networks/create', createBody).respond(201);
expectGetNetwork();
$scope.addNetwork(createBody);
$httpBackend.flush();
});
function expectGetNetwork() {
$httpBackend.expectGET('dockerapi/networks').respond([
function expectGetNetwork() {
$httpBackend.expectGET('dockerapi/networks').respond([
{
Name: 'bridge',
Id: 'f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566',
Scope: 'local',
Driver: 'bridge',
IPAM: {
Driver: 'default',
Config: [
{
"Name": "bridge",
"Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566",
"Scope": "local",
"Driver": "bridge",
"IPAM": {
"Driver": "default",
"Config": [
{
"Subnet": "172.17.0.0/16"
}
]
},
"Containers": {
"39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": {
"EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
}
Subnet: '172.17.0.0/16',
},
{
"Name": "none",
"Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794",
"Scope": "local",
"Driver": "null",
"IPAM": {
"Driver": "default",
"Config": []
},
"Containers": {},
"Options": {}
},
{
"Name": "host",
"Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e",
"Scope": "local",
"Driver": "host",
"IPAM": {
"Driver": "default",
"Config": []
},
"Containers": {},
"Options": {}
}
]);
}
});
],
},
Containers: {
'39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867': {
EndpointID: 'ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda',
MacAddress: '02:42:ac:11:00:02',
IPv4Address: '172.17.0.2/16',
IPv6Address: '',
},
},
Options: {
'com.docker.network.bridge.default_bridge': 'true',
'com.docker.network.bridge.enable_icc': 'true',
'com.docker.network.bridge.enable_ip_masquerade': 'true',
'com.docker.network.bridge.host_binding_ipv4': '0.0.0.0',
'com.docker.network.bridge.name': 'docker0',
'com.docker.network.driver.mtu': '1500',
},
},
{
Name: 'none',
Id: 'e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794',
Scope: 'local',
Driver: 'null',
IPAM: {
Driver: 'default',
Config: [],
},
Containers: {},
Options: {},
},
{
Name: 'host',
Id: '13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e',
Scope: 'local',
Driver: 'host',
IPAM: {
Driver: 'default',
Config: [],
},
Containers: {},
Options: {},
},
]);
}
});

View file

@ -1,247 +1,265 @@
describe('startContainerController', function () {
var scope, $location, createController, mockContainer, $httpBackend;
var scope, $location, createController, mockContainer, $httpBackend;
beforeEach(angular.mock.module('portainer'));
beforeEach(angular.mock.module('portainer'));
beforeEach(inject(function ($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();
beforeEach(inject(function ($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();
createController = function () {
return $controller('StartContainerController', {
'$scope': scope
});
};
createController = function () {
return $controller('StartContainerController', {
$scope: scope,
});
};
angular.mock.inject(function (_Container_, _$httpBackend_) {
mockContainer = _Container_;
$httpBackend = _$httpBackend_;
});
}));
function expectGetContainers() {
$httpBackend.expectGET('dockerapi/containers/json?all=1').respond([{
'Command': './portainer -e /docker.sock',
'Created': 1421817232,
'Id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
'Image': 'portainer:latest',
'Names': ['/portainer'],
'Ports': [{
'IP': '0.0.0.0',
'PrivatePort': 9000,
'PublicPort': 9000,
'Type': 'tcp'
}],
'Status': 'Up 2 minutes'
}]);
}
describe('Create and start a container with port bindings', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
'name': 'container-name',
'ExposedPorts': {
'9000/tcp': {}
},
'HostConfig': {
'PortBindings': {
'9000/tcp': [{
'HostPort': '9999',
'HostIp': '10.20.10.15'
}]
}
}
};
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
'Id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
'id': id,
'Warnings': null
});
scope.config.name = 'container-name';
scope.config.HostConfig.PortBindings = [{
ip: '10.20.10.15',
extPort: '9999',
intPort: '9000'
}];
scope.create();
$httpBackend.flush();
});
angular.mock.inject(function (_Container_, _$httpBackend_) {
mockContainer = _Container_;
$httpBackend = _$httpBackend_;
});
}));
function expectGetContainers() {
$httpBackend.expectGET('dockerapi/containers/json?all=1').respond([
{
Command: './portainer -e /docker.sock',
Created: 1421817232,
Id: 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
Image: 'portainer:latest',
Names: ['/portainer'],
Ports: [
{
IP: '0.0.0.0',
PrivatePort: 9000,
PublicPort: 9000,
Type: 'tcp',
},
],
Status: 'Up 2 minutes',
},
]);
}
describe('Create and start a container with environment variables', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
'name': 'container-name',
'Env': ['SHELL=/bin/bash', 'TERM=xterm-256color']
};
describe('Create and start a container with port bindings', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
name: 'container-name',
ExposedPorts: {
'9000/tcp': {},
},
HostConfig: {
PortBindings: {
'9000/tcp': [
{
HostPort: '9999',
HostIp: '10.20.10.15',
},
],
},
},
};
expectGetContainers();
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
'Id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
'id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
Id: id,
Warnings: null,
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
id: id,
Warnings: null,
});
scope.config.name = 'container-name';
scope.config.Env = [{
name: 'SHELL',
value: '/bin/bash'
}, {
name: 'TERM',
value: 'xterm-256color'
}];
scope.config.name = 'container-name';
scope.config.HostConfig.PortBindings = [
{
ip: '10.20.10.15',
extPort: '9999',
intPort: '9000',
},
];
scope.create();
$httpBackend.flush();
});
scope.create();
$httpBackend.flush();
});
});
describe('Create and start a container with labels', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
'name': 'container-name',
'Labels': {
"org.foo.bar": "Baz",
"com.biz.baz": "Boo"
}
};
describe('Create and start a container with environment variables', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
name: 'container-name',
Env: ['SHELL=/bin/bash', 'TERM=xterm-256color'],
};
expectGetContainers();
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
'Id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
'id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
Id: id,
Warnings: null,
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
id: id,
Warnings: null,
});
scope.config.name = 'container-name';
scope.config.Labels = [{
key: 'org.foo.bar',
value: 'Baz'
}, {
key: 'com.biz.baz',
value: 'Boo'
}];
scope.config.name = 'container-name';
scope.config.Env = [
{
name: 'SHELL',
value: '/bin/bash',
},
{
name: 'TERM',
value: 'xterm-256color',
},
];
scope.create();
$httpBackend.flush();
});
scope.create();
$httpBackend.flush();
});
});
describe('Create and start a container with volumesFrom', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
HostConfig: {
'VolumesFrom': ['parent', 'other:ro']
},
'name': 'container-name'
};
describe('Create and start a container with labels', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
name: 'container-name',
Labels: {
'org.foo.bar': 'Baz',
'com.biz.baz': 'Boo',
},
};
expectGetContainers();
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
'Id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
'id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
Id: id,
Warnings: null,
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
id: id,
Warnings: null,
});
scope.config.name = 'container-name';
scope.config.HostConfig.VolumesFrom = [{name: 'parent'}, {name: 'other:ro'}];
scope.config.name = 'container-name';
scope.config.Labels = [
{
key: 'org.foo.bar',
value: 'Baz',
},
{
key: 'com.biz.baz',
value: 'Boo',
},
];
scope.create();
$httpBackend.flush();
});
scope.create();
$httpBackend.flush();
});
});
describe('Create and start a container with multiple options', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
Volumes: ['/var/www'],
SecurityOpts: ['label:type:svirt_apache'],
HostConfig: {
Binds: ['/app:/app'],
Links: ['web:db'],
Dns: ['8.8.8.8'],
DnsSearch: ['example.com'],
CapAdd: ['cap_sys_admin'],
CapDrop: ['cap_foo_bar'],
Devices: [{
'PathOnHost': '/dev/deviceName',
'PathInContainer': '/dev/deviceName',
'CgroupPermissions': 'mrw'
}],
LxcConf: {'lxc.utsname': 'docker'},
ExtraHosts: ['hostname:127.0.0.1'],
RestartPolicy: {name: 'always', MaximumRetryCount: 5}
},
name: 'container-name'
};
describe('Create and start a container with volumesFrom', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
HostConfig: {
VolumesFrom: ['parent', 'other:ro'],
},
name: 'container-name',
};
expectGetContainers();
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
'Id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
'id': id,
'Warnings': null
});
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
Id: id,
Warnings: null,
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
id: id,
Warnings: null,
});
scope.config.name = 'container-name';
scope.config.Volumes = [{name: '/var/www'}];
scope.config.SecurityOpts = [{name: 'label:type:svirt_apache'}];
scope.config.NetworkDisabled = true;
scope.config.Tty = true;
scope.config.OpenStdin = true;
scope.config.StdinOnce = true;
scope.config.name = 'container-name';
scope.config.HostConfig.VolumesFrom = [{ name: 'parent' }, { name: 'other:ro' }];
scope.config.HostConfig.Binds = [{name: '/app:/app'}];
scope.config.HostConfig.Links = [{name: 'web:db'}];
scope.config.HostConfig.Dns = [{name: '8.8.8.8'}];
scope.config.HostConfig.DnsSearch = [{name: 'example.com'}];
scope.config.HostConfig.CapAdd = [{name: 'cap_sys_admin'}];
scope.config.HostConfig.CapDrop = [{name: 'cap_foo_bar'}];
scope.config.HostConfig.PublishAllPorts = true;
scope.config.HostConfig.Privileged = true;
scope.config.HostConfig.RestartPolicy = {name: 'always', MaximumRetryCount: 5};
scope.config.HostConfig.Devices = [{
'PathOnHost': '/dev/deviceName',
'PathInContainer': '/dev/deviceName',
'CgroupPermissions': 'mrw'
}];
scope.config.HostConfig.LxcConf = [{name: 'lxc.utsname', value: 'docker'}];
scope.config.HostConfig.ExtraHosts = [{host: 'hostname', ip: '127.0.0.1'}];
scope.create();
$httpBackend.flush();
});
scope.create();
$httpBackend.flush();
});
});
});
describe('Create and start a container with multiple options', function () {
it('should issue a correct create request to the Docker remote API', function () {
var controller = createController();
var id = '6abd8bfba81cf8a05a76a4bdefcb36c4b66cd02265f4bfcd0e236468696ebc6c';
var expectedBody = {
Volumes: ['/var/www'],
SecurityOpts: ['label:type:svirt_apache'],
HostConfig: {
Binds: ['/app:/app'],
Links: ['web:db'],
Dns: ['8.8.8.8'],
DnsSearch: ['example.com'],
CapAdd: ['cap_sys_admin'],
CapDrop: ['cap_foo_bar'],
Devices: [
{
PathOnHost: '/dev/deviceName',
PathInContainer: '/dev/deviceName',
CgroupPermissions: 'mrw',
},
],
LxcConf: { 'lxc.utsname': 'docker' },
ExtraHosts: ['hostname:127.0.0.1'],
RestartPolicy: { name: 'always', MaximumRetryCount: 5 },
},
name: 'container-name',
};
expectGetContainers();
$httpBackend.expectPOST('dockerapi/containers/create?name=container-name', expectedBody).respond({
Id: id,
Warnings: null,
});
$httpBackend.expectPOST('dockerapi/containers/' + id + '/start').respond({
id: id,
Warnings: null,
});
scope.config.name = 'container-name';
scope.config.Volumes = [{ name: '/var/www' }];
scope.config.SecurityOpts = [{ name: 'label:type:svirt_apache' }];
scope.config.NetworkDisabled = true;
scope.config.Tty = true;
scope.config.OpenStdin = true;
scope.config.StdinOnce = true;
scope.config.HostConfig.Binds = [{ name: '/app:/app' }];
scope.config.HostConfig.Links = [{ name: 'web:db' }];
scope.config.HostConfig.Dns = [{ name: '8.8.8.8' }];
scope.config.HostConfig.DnsSearch = [{ name: 'example.com' }];
scope.config.HostConfig.CapAdd = [{ name: 'cap_sys_admin' }];
scope.config.HostConfig.CapDrop = [{ name: 'cap_foo_bar' }];
scope.config.HostConfig.PublishAllPorts = true;
scope.config.HostConfig.Privileged = true;
scope.config.HostConfig.RestartPolicy = { name: 'always', MaximumRetryCount: 5 };
scope.config.HostConfig.Devices = [
{
PathOnHost: '/dev/deviceName',
PathInContainer: '/dev/deviceName',
CgroupPermissions: 'mrw',
},
];
scope.config.HostConfig.LxcConf = [{ name: 'lxc.utsname', value: 'docker' }];
scope.config.HostConfig.ExtraHosts = [{ host: 'hostname', ip: '127.0.0.1' }];
scope.create();
$httpBackend.flush();
});
});
});

View file

@ -1,31 +1,31 @@
describe("StatsController", function () {
var $scope, $httpBackend, $routeParams;
describe('StatsController', function () {
var $scope, $httpBackend, $routeParams;
beforeEach(angular.mock.module('portainer'));
beforeEach(angular.mock.module('portainer'));
beforeEach(inject(function (_$rootScope_, _$httpBackend_, $controller, _$routeParams_) {
$scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$controller('StatsController', {
'$scope': $scope,
'$routeParams': $routeParams
});
}));
beforeEach(inject(function (_$rootScope_, _$httpBackend_, $controller, _$routeParams_) {
$scope = _$rootScope_.$new();
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$controller('StatsController', {
$scope: $scope,
$routeParams: $routeParams,
});
}));
//it("should test controller initialize", function () {
// $httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/stats?stream=false').respond(200);
// //expect($scope.ps_args).toBeDefined();
// $httpBackend.flush();
//});
//
//it("a correct top request to the Docker remote API", function () {
// //$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=').respond(200);
// //$routeParams.id = '123456789123456789123456789';
// //$scope.ps_args = 'aux';
// //$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=' + $scope.ps_args).respond(200);
// //$scope.getTop();
// //$httpBackend.flush();
//});
});
//it("should test controller initialize", function () {
// $httpBackend.expectGET('dockerapi/containers/b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f/stats?stream=false').respond(200);
// //expect($scope.ps_args).toBeDefined();
// $httpBackend.flush();
//});
//
//it("a correct top request to the Docker remote API", function () {
// //$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=').respond(200);
// //$routeParams.id = '123456789123456789123456789';
// //$scope.ps_args = 'aux';
// //$httpBackend.expectGET('dockerapi/containers/' + $routeParams.id + '/top?ps_args=' + $scope.ps_args).respond(200);
// //$scope.getTop();
// //$httpBackend.flush();
//});
});

View file

@ -1,64 +1,63 @@
describe('VolumesController', function () {
var $scope, $httpBackend, $routeParams;
var $scope, $httpBackend, $routeParams;
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$controller('VolumesController', {
'$scope': $scope,
'$routeParams': $routeParams
});
}));
it('initializes correctly', function () {
expectGetVolumes();
$httpBackend.flush();
beforeEach(module('portainer'));
beforeEach(inject(function (_$httpBackend_, $controller, _$routeParams_) {
$scope = {};
$httpBackend = _$httpBackend_;
$routeParams = _$routeParams_;
$controller('VolumesController', {
$scope: $scope,
$routeParams: $routeParams,
});
}));
it('initializes correctly', function () {
expectGetVolumes();
$httpBackend.flush();
});
it('issues correct remove calls to the remote API', function () {
expectGetVolumes();
$httpBackend.flush();
$scope.volumes[0].Checked = true;
$scope.volumes[2].Checked = true;
$httpBackend.expectDELETE('dockerapi/volumes/tardis').respond(200);
$httpBackend.expectDELETE('dockerapi/volumes/bar').respond(200);
$scope.removeAction();
$httpBackend.flush();
it('issues correct remove calls to the remote API', function () {
expectGetVolumes();
$httpBackend.flush();
$scope.volumes[0].Checked = true;
$scope.volumes[2].Checked = true;
$httpBackend.expectDELETE('dockerapi/volumes/tardis').respond(200);
$httpBackend.expectDELETE('dockerapi/volumes/bar').respond(200);
$scope.removeAction();
$httpBackend.flush();
});
it('issues a correct volume creation call to the remote API', function () {
expectGetVolumes();
var createBody = {
Name: 'tardis',
Driver: 'local',
};
$httpBackend.expectPOST('dockerapi/volumes/create', createBody).respond(201);
expectGetVolumes();
$scope.addVolume(createBody);
$httpBackend.flush();
});
function expectGetVolumes() {
$httpBackend.expectGET('dockerapi/volumes').respond({
Volumes: [
{
Name: 'tardis',
Driver: 'local',
Mountpoint: '/var/lib/docker/volumes/tardis',
},
{
Name: 'foo',
Driver: 'local',
Mountpoint: '/var/lib/docker/volumes/foo',
},
{
Name: 'bar',
Driver: 'local',
Mountpoint: '/var/lib/docker/volumes/bar',
},
],
});
it('issues a correct volume creation call to the remote API', function () {
expectGetVolumes();
var createBody = {
"Name": "tardis",
"Driver": "local"
};
$httpBackend.expectPOST('dockerapi/volumes/create', createBody).respond(201);
expectGetVolumes();
$scope.addVolume(createBody);
$httpBackend.flush();
});
function expectGetVolumes() {
$httpBackend.expectGET('dockerapi/volumes').respond({
"Volumes": [
{
"Name": "tardis",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/tardis"
},
{
"Name": "foo",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/foo"
},
{
"Name": "bar",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/bar"
}
]
});
}
});
}
});

View file

@ -1,110 +1,109 @@
describe('filters', function () {
beforeEach(module('portainer.filters'));
beforeEach(module('portainer.filters'));
describe('truncate', function () {
it('should truncate the string to 10 characters ending in "..." by default', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long')).toBe('this is...');
}));
describe('truncate', function () {
it('should truncate the string to 10 characters ending in "..." by default', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long')).toBe('this is...');
}));
it('should truncate the string to 7 characters ending in "..."', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long', 7)).toBe('this...');
}));
it('should truncate the string to 7 characters ending in "..."', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long', 7)).toBe('this...');
}));
it('should truncate the string to 10 characters ending in "???"', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long', 10, '???')).toBe('this is???');
}));
});
it('should truncate the string to 10 characters ending in "???"', inject(function (truncateFilter) {
expect(truncateFilter('this is 20 chars long', 10, '???')).toBe('this is???');
}));
});
describe('getstatetext', function () {
describe('getstatetext', function () {
it('should return an empty string when state is undefined', inject(function (getstatetextFilter) {
expect(getstatetextFilter(undefined)).toBe('');
}));
it('should return an empty string when state is undefined', inject(function (getstatetextFilter) {
expect(getstatetextFilter(undefined)).toBe('');
}));
it('should detect a Ghost state', inject(function (getstatetextFilter) {
var state = {
Ghost: true,
Running: true,
Paused: false,
};
expect(getstatetextFilter(state)).toBe('Ghost');
}));
it('should detect a Ghost state', inject(function (getstatetextFilter) {
var state = {
Ghost: true,
Running: true,
Paused: false
};
expect(getstatetextFilter(state)).toBe('Ghost');
}));
it('should detect a Paused state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: true,
Paused: true,
};
expect(getstatetextFilter(state)).toBe('Running (Paused)');
}));
it('should detect a Paused state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: true,
Paused: true
};
expect(getstatetextFilter(state)).toBe('Running (Paused)');
}));
it('should detect a Running state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: true,
Paused: false,
};
expect(getstatetextFilter(state)).toBe('Running');
}));
it('should detect a Running state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: true,
Paused: false
};
expect(getstatetextFilter(state)).toBe('Running');
}));
it('should detect a Stopped state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: false,
Paused: false,
};
expect(getstatetextFilter(state)).toBe('Stopped');
}));
});
it('should detect a Stopped state', inject(function (getstatetextFilter) {
var state = {
Ghost: false,
Running: false,
Paused: false
};
expect(getstatetextFilter(state)).toBe('Stopped');
}));
});
describe('getstatelabel', function () {
it('should return default when state is undefined', inject(function (getstatelabelFilter) {
expect(getstatelabelFilter(undefined)).toBe('label-default');
}));
describe('getstatelabel', function () {
it('should return default when state is undefined', inject(function (getstatelabelFilter) {
expect(getstatelabelFilter(undefined)).toBe('label-default');
}));
it('should return label-important when a ghost state is detected', inject(function (getstatelabelFilter) {
var state = {
Ghost: true,
Running: true,
Paused: false,
};
expect(getstatelabelFilter(state)).toBe('label-important');
}));
it('should return label-important when a ghost state is detected', inject(function (getstatelabelFilter) {
var state = {
Ghost: true,
Running: true,
Paused: false
};
expect(getstatelabelFilter(state)).toBe('label-important');
}));
it('should return label-success when a running state is detected', inject(function (getstatelabelFilter) {
var state = {
Ghost: false,
Running: true,
Paused: false,
};
expect(getstatelabelFilter(state)).toBe('label-success');
}));
});
it('should return label-success when a running state is detected', inject(function (getstatelabelFilter) {
var state = {
Ghost: false,
Running: true,
Paused: false
};
expect(getstatelabelFilter(state)).toBe('label-success');
}));
});
describe('containername', function () {
it('should strip the leading slash from container name', inject(function (containernameFilter) {
var container = {
Names: ['/elegant_ardinghelli'],
};
describe('containername', function () {
it('should strip the leading slash from container name', inject(function (containernameFilter) {
var container = {
Names: ['/elegant_ardinghelli']
};
expect(containernameFilter(container)).toBe('elegant_ardinghelli');
}));
});
expect(containernameFilter(container)).toBe('elegant_ardinghelli');
}));
});
describe('repotag', function () {
it('should not display empty repo tag', inject(function (repotagFilter) {
var image = {
RepoTags: ['<none>:<none>'],
};
expect(repotagFilter(image)).toBe('');
}));
describe('repotag', function () {
it('should not display empty repo tag', inject(function (repotagFilter) {
var image = {
RepoTags: ['<none>:<none>']
};
expect(repotagFilter(image)).toBe('');
}));
it('should display a normal repo tag', inject(function (repotagFilter) {
var image = {
RepoTags: ['ubuntu:latest']
};
expect(repotagFilter(image)).toBe('ubuntu:latest');
}));
});
it('should display a normal repo tag', inject(function (repotagFilter) {
var image = {
RepoTags: ['ubuntu:latest'],
};
expect(repotagFilter(image)).toBe('ubuntu:latest');
}));
});
});