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

Add rename feature

This commit is contained in:
Houssem BELHADJ AHMED 2015-03-12 22:28:01 +01:00
parent f29eaa28ba
commit c971189286
9 changed files with 99 additions and 7 deletions

View file

@ -0,0 +1,57 @@
describe('ContainerController', function() {
var $scope, $httpBackend, mockContainer, $routeParams;
beforeEach(module('dockerui'));
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': 'dockerui:latest',
'Name': '/dockerui'
});
}
it("a correct create request to the Docker remote API", function () {
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
$scope.container = {
'Created': 1421817232,
'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
'Image': 'dockerui:latest',
'Name': '/dockerui'
};
$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

@ -0,0 +1,201 @@
describe('startContainerController', function() {
var scope, $location, createController, mockContainer, $httpBackend;
beforeEach(angular.mock.module('dockerui'));
beforeEach(inject(function($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();
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': './dockerui -e /docker.sock',
'Created': 1421817232,
'Id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
'Image': 'dockerui:latest',
'Names': ['/dockerui'],
'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();
});
});
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();
$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.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'
};
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.VolumesFrom = [{name: 'parent'}, {name:'other:ro'}];
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

@ -0,0 +1,165 @@
describe('filters', function () {
beforeEach(module('dockerui.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...');
}));
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???');
}));
});
describe('statusbadge', function () {
it('should be "important" when input is "Ghost"', inject(function(statusbadgeFilter) {
expect(statusbadgeFilter('Ghost')).toBe('important');
}));
it('should be "success" when input is "Exit 0"', inject(function(statusbadgeFilter) {
expect(statusbadgeFilter('Exit 0')).toBe('success');
}));
it('should be "warning" when exit code is non-zero', inject(function(statusbadgeFilter) {
expect(statusbadgeFilter('Exit 1')).toBe('warning');
}));
});
describe('getstatetext', function () {
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 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 Stopped state', inject(function(getstatetextFilter) {
var state = {
Ghost: false,
Running: false,
Paused: false
};
expect(getstatetextFilter(state)).toBe('Stopped');
}));
});
describe('getstatelabel', function () {
it('should return an empty string when state is undefined', inject(function(getstatelabelFilter) {
expect(getstatelabelFilter(undefined)).toBe('');
}));
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');
}));
});
describe('humansize', function () {
it('should return n/a when size is zero', inject(function(humansizeFilter) {
expect(humansizeFilter(0)).toBe('n/a');
}));
it('should handle Bytes values', inject(function(humansizeFilter) {
expect(humansizeFilter(512)).toBe('512 Bytes');
}));
it('should handle KB values', inject(function(humansizeFilter) {
expect(humansizeFilter(5120)).toBe('5 KB');
}));
it('should handle MB values', inject(function(humansizeFilter) {
expect(humansizeFilter(5 * Math.pow(10, 6))).toBe('5 MB');
}));
it('should handle GB values', inject(function(humansizeFilter) {
expect(humansizeFilter(5 * Math.pow(10, 9))).toBe('5 GB');
}));
it('should handle TB values', inject(function(humansizeFilter) {
expect(humansizeFilter(5 * Math.pow(10, 12))).toBe('5 TB');
}));
});
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');
}));
});
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');
}));
});
describe('getdate', function () {
it('should convert the Docker date to a human readable form', inject(function(getdateFilter) {
expect(getdateFilter(1420424998)).toBe('Mon Jan 05 2015');
}));
});
describe('errorMsgFilter', function() {
it('should convert the $resource object to a string message',
inject(function(errorMsgFilter) {
var response = {'0':'C','1':'o','2':'n','3':'f','4':'l','5':'i','6':'c','7':'t','8':',','9':' ','10':'T','11':'h','12':'e','13':' ','14':'n','15':'a','16':'m','17':'e','18':' ','19':'u','20':'b','21':'u','22':'n','23':'t','24':'u','25':'-','26':'s','27':'l','28':'e','29':'e','30':'p','31':'-','32':'r','33':'u','34':'n','35':'t','36':'i','37':'m','38':'e','39':' ','40':'i','41':'s','42':' ','43':'a','44':'l','45':'r','46':'e','47':'a','48':'d','49':'y','50':' ','51':'a','52':'s','53':'s','54':'i','55':'g','56':'n','57':'e','58':'d','59':' ','60':'t','61':'o','62':' ','63':'b','64':'6','65':'9','66':'e','67':'5','68':'3','69':'a','70':'6','71':'2','72':'2','73':'c','74':'8','75':'.','76':' ','77':'Y','78':'o','79':'u','80':' ','81':'h','82':'a','83':'v','84':'e','85':' ','86':'t','87':'o','88':' ','89':'d','90':'e','91':'l','92':'e','93':'t','94':'e','95':' ','96':'(','97':'o','98':'r','99':' ','100':'r','101':'e','102':'n','103':'a','104':'m','105':'e','106':')','107':' ','108':'t','109':'h','110':'a','111':'t','112':' ','113':'c','114':'o','115':'n','116':'t','117':'a','118':'i','119':'n','120':'e','121':'r','122':' ','123':'t','124':'o','125':' ','126':'b','127':'e','128':' ','129':'a','130':'b','131':'l','132':'e','133':' ','134':'t','135':'o','136':' ','137':'a','138':'s','139':'s','140':'i','141':'g','142':'n','143':' ','144':'u','145':'b','146':'u','147':'n','148':'t','149':'u','150':'-','151':'s','152':'l','153':'e','154':'e','155':'p','156':'-','157':'r','158':'u','159':'n','160':'t','161':'i','162':'m','163':'e','164':' ','165':'t','166':'o','167':' ','168':'a','169':' ','170':'c','171':'o','172':'n','173':'t','174':'a','175':'i','176':'n','177':'e','178':'r','179':' ','180':'a','181':'g','182':'a','183':'i','184':'n','185':'.','186':'\n','$promise':{},'$resolved':true};
var message = 'Conflict, The name ubuntu-sleep-runtime is already assigned to b69e53a622c8. You have to delete (or rename) that container to be able to assign ubuntu-sleep-runtime to a container again.\n';
expect(errorMsgFilter(response)).toBe(message);
}));
});
});