Skip to content

Fix ls command to properly list services by name #53

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if(program.ls){
list.all();
}
else{
ps.prs(program.ls);
list.prs(program.ls);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
},
execution : (keyMap)=>{
var name = keyMap.name;
var cmd = "docker service ls -f 'name="+name+"'|grep -w '"+name+"'";
var cmd = "docker service ls -f 'name="+name+"'";
chp.exec(cmd,(e, stdout, stderr)=> {
if(stdout){
console.log(stdout);
Expand Down
53 changes: 53 additions & 0 deletions test/test-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var should = require('should');
var chp = require('child_process');
var list = require('../lib/list');

describe('List Command', function() {
describe('Service filtering', function() {
it('should generate correct docker command for specific service', function(done) {
// Mock child_process.exec to capture the command
var originalExec = chp.exec;
var capturedCommand = '';

chp.exec = function(cmd, callback) {
capturedCommand = cmd;
// Simulate successful execution
callback(null, 'ID NAME MODE REPLICAS IMAGE\n', '');
};

// Test the prs function
list.prs('webapp');

// Restore original exec
chp.exec = originalExec;

// Verify the command is correct
capturedCommand.should.equal("docker service ls -f 'name=webapp'");
done();
});

it('should generate correct docker command for all services', function(done) {
// Mock child_process.exec to capture the command
var originalExec = chp.exec;
var capturedCommand = '';

chp.exec = function(cmd, callback) {
capturedCommand = cmd;
// Simulate successful execution
callback(null, 'ID NAME MODE REPLICAS IMAGE\n', '');
};

// Test the all function
list.all();

// Restore original exec
chp.exec = originalExec;

// Verify the command is correct
capturedCommand.should.equal("docker service ls");
done();
});
});
});