Skip to content
Permalink
Browse files
  • Loading branch information
purplecabbage committed Jun 20, 2014
2 parents 1cecf6a + f658489 commit aa2a04be79ef70e327d70af6f9277d2494ebd91a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
@@ -41,7 +41,7 @@ describe('fetch', function() {
var xml, rm, sym, mkdir, cp, save_metadata;
beforeEach(function() {
xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
getroot:function() { return {attrib:{id:'id'}};}
getroot:function() { return {attrib:{id:'id', version:'version'}};}
});
rm = spyOn(shell, 'rm');
sym = spyOn(fs, 'symlinkSync');
@@ -80,6 +80,19 @@ describe('fetch', function() {
expect(1).toBe(1);
});
});
it('should fail when the expected ID with version specified doesn\'t match', function(done) {
fetch(test_plugin, temp, { expected_id: 'id@wrongVersion' })
.then(function() {
expect('this call').toBe('fail');
}, function(err) {
expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion" but got "id@version".');
}).fin(done);
});
it('should succeed when the plugin version specified is correct', function(done) {
wrapper(fetch(test_plugin, temp, { expected_id: 'id@version' }), done, function() {
expect(1).toBe(1);
});
});
});
describe('git plugins', function() {
var clone, save_metadata, done, xml;
@@ -93,7 +106,7 @@ describe('fetch', function() {
save_metadata = spyOn(metadata, 'save_fetch_metadata');
done = false;
xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
getroot:function() { return {attrib:{id:'id'}};}
getroot:function() { return {attrib:{id:'id', version:'version'}};}
});
});
it('should call clonePluginGitRepo for https:// and git:// based urls', function() {
@@ -186,18 +199,31 @@ describe('fetch', function() {
expect(''+err).toContain('Expected fetched plugin to have ID "wrongID" but got "id".');
}).fin(done);
});
it('should fail when the expected ID with version specified doesn\'t match', function(done) {
fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'id@wrongVersion' })
.then(function() {
expect('this call').toBe('fail');
}, function(err) {
expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion" but got "id@version".');
}).fin(done);
});
it('should succeed when the expected ID is correct', function(done) {
wrapper(fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'id' }), done, function() {
expect(1).toBe(1);
});
});
it('should succeed when the plugin version specified is correct', function(done) {
wrapper(fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'id@version' }), done, function() {
expect(1).toBe(1);
});
});
});
describe('registry plugins', function() {
var pluginId = 'dummyplugin', sFetch;
var xml, rm, sym, mkdir, cp, save_metadata;
beforeEach(function() {
xml = spyOn(xml_helpers, 'parseElementtreeSync').andReturn({
getroot:function() { return {attrib:{id:'id'}};}
getroot:function() { return {attrib:{id:'id', version:'version'}};}
});
rm = spyOn(shell, 'rm');
sym = spyOn(fs, 'symlinkSync');
@@ -220,10 +246,23 @@ describe('fetch', function() {
expect(''+err).toContain('Expected fetched plugin to have ID "wrongID" but got "id".');
}).fin(done);
});
it('should fail when the expected ID with version specified doesn\'t match', function(done) {
fetch(pluginId, temp, { expected_id: 'id@wrongVersion' })
.then(function() {
expect('this call').toBe('fail');
}, function(err) {
expect(''+err).toContain('Expected fetched plugin to have ID "id@wrongVersion" but got "id@version".');
}).fin(done);
});
it('should succeed when the expected ID is correct', function(done) {
wrapper(fetch(pluginId, temp, { expected_id: 'id' }), done, function() {
expect(1).toBe(1);
});
});
it('should succeed when the plugin version specified is correct', function(done) {
wrapper(fetch(pluginId, temp, { expected_id: 'id@version' }), done, function() {
expect(1).toBe(1);
});
});
});
});
@@ -137,10 +137,21 @@ function readId(dir) {
return plugin_id;
}

function readVersion(dir) {
var xml_path = path.join(dir, 'plugin.xml');
var et = xml_helpers.parseElementtreeSync(path.join(dir, 'plugin.xml'));
var plugin_id = et.getroot().attrib.version;
return plugin_id;
}

// Helper function for checking expected plugin IDs against reality.
function checkID(expected_id, dir) {
if ( expected_id ) {
var id = readId(dir);
// if id with specific version provided, append version to id
if (expected_id.split('@').length > 1) {
id = id + "@" + readVersion(dir);
}
if (expected_id != id) {
throw new Error('Expected fetched plugin to have ID "' + expected_id + '" but got "' + id + '".');
}

0 comments on commit aa2a04b

Please sign in to comment.