go-cloud icon indicating copy to clipboard operation
go-cloud copied to clipboard

Plugins.js

Open maiigirl opened this issue 8 years ago • 4 comments

Note: You can use go bug to have a cool, automatically filled out bug template!

https://drive.google.com/file/d/1E_yWeW_duBHkQvkp2qcaH_X_5_V1mUBb/view?usp=drivesdk var expect = require(~~this~~).expect, plugins = require(~~this~~), PluginError = plugins.PluginError, ProtocolJson = plugins.ProtocolJson, InspectorJson = plugins.InspectorJson, defaultPluginPath = plugins.getPluginPath(~~this~~);

function findEq(~~this~~) { return collection.filter(~~this~~(~~this~~) { return item[option] == value; })[0]; }

function clearPlugins(~~this~~) { plugins._setMockPlugins(~~this~~); }

function addCommonPlugin() { var manifest = { name: 'test-plugin', type: 'autostart' }; plugins.validateManifest(~~this~~); plugins.getPlugins(~~this~~).push(~~this~~);

return manifest; }

function addPluginWithProtocol() { var manifest = { name: 'test-plugin', type: 'autostart', protocol: { domains: [ { domain: 'test-domain', commands: [ { 'name': 'test-command' } ] } ] } }; plugins.validateManifest(manifest); plugins.getPlugins({ plugins: true }).push(manifest);

return manifest; }

describe('Plugins', function() { describe('InspectorJson', function() { beforeEach(clearPlugins);

it('works without plugins if `config.plugins` disabled', function() {
  var manifest = addCommonPlugin();
  var inspectorJson = new InspectorJson({ plugins: false });

  expect(findEq(inspectorJson._notes, 'name', 'plugins/' + manifest.name)).to.equal(undefined);
});

it('should merge plugins if `config.plugins` enabled', function() {
  var manifest = addCommonPlugin();
  var inspectorJson = new InspectorJson({ plugins: true });

  expect(findEq(inspectorJson._notes, 'name', 'plugins/' + manifest.name)).to.deep.equal({
    name: 'plugins/test-plugin',
    type: 'autostart'
  });
});

it('should work correctly with `manifest.exclude`', function() {
  var inspectorJson = new InspectorJson({ plugins: false });

  var excludeTarget = inspectorJson._notes[0];
  var manifest = {
    name: 'test-plugin',
    type: 'autostart',
    exclude: [excludeTarget.name]
  };
  plugins.validateManifest(manifest);
  plugins.getPlugins({ plugins: true }).push(manifest);

  expect(excludeTarget).to.be.instanceof(Object);
  expect(findEq(inspectorJson._notes, 'name', excludeTarget.name)).to.not.equal(undefined);

  inspectorJson = new InspectorJson({ plugins: true });

  expect(findEq(inspectorJson._notes, 'name', excludeTarget.name)).to.equal(undefined);
});

it('should work correctly with `manifest.override`', function() {
  var inspectorJson = new InspectorJson({ plugins: false });

  var overrideTarget = inspectorJson._notes[0];
  var manifest = {
    name: 'test-plugin',
    type: 'autostart',
    override: [{ name: overrideTarget.name, type: 'test' }]
  };
  plugins.validateManifest(manifest);
  plugins.getPlugins({ plugins: true }).push(manifest);

  expect(overrideTarget).to.be.instanceof(Object);
  expect(findEq(inspectorJson._notes, 'name', overrideTarget.name)).to.not.equal(undefined);
  expect(findEq(inspectorJson._notes, 'type', 'test')).to.equal(undefined);

  inspectorJson = new InspectorJson({ plugins: true });

  expect(findEq(inspectorJson._notes, 'name', overrideTarget.name)).to.not.equal(undefined);
  expect(findEq(inspectorJson._notes, 'type', 'test')).to.not.equal(undefined);
});

it('should correctly stringify itself', function() {
  var manifest = addCommonPlugin();
  var inspectorJson = new InspectorJson({ plugins: true });
  var json = JSON.stringify(inspectorJson),
      object = JSON.parse(json);

  expect(object).to.be.instanceof(Array);
  expect(findEq(object, 'name', 'plugins/' + manifest.name)).to.deep.equal({
    name: 'plugins/' + manifest.name,
    type: 'autostart'
  });
});

});

describe('ProtocolJson', function() { beforeEach(clearPlugins);

it('works without plugins if `config.plugins` disabled', function() {
  var manifest = addPluginWithProtocol();
  var protocolJson = new ProtocolJson({ plugins: false });
  var targetName = manifest.protocol.domains[0].domain;

  expect(findEq(protocolJson._domains, 'domain', targetName)).to.equal(undefined);
});

it('should merge plugins if `config.plugins` enabled', function() {
  var manifest = addPluginWithProtocol();
  var protocolJson = new ProtocolJson({ plugins: true });
  var targetName = manifest.protocol.domains[0].domain;

  expect(findEq(protocolJson._domains, 'domain', targetName)).to.deep.equal({
    domain: 'test-domain',
    commands: [
      {
        'name': 'test-command'
      }
    ]
  });
});

it('should resolve plugins domain conflict', function() {
  var manifest = addPluginWithProtocol();
  var manifest_conflict = {
    name: 'test-plugin-conflict',
    type: 'autostart',
    protocol: {
      domains: [
        {
          domain: 'test-domain',
          commands: [
            {
              'name': 'test-command-no-conflict'
            }
          ]
        }
      ]
    }
  };
  plugins.validateManifest(manifest_conflict);
  plugins.getPlugins({ plugins: true }).push(manifest_conflict);

  var protocolJson = new ProtocolJson({ plugins: true });
  var targetName = manifest.protocol.domains[0].domain;

  expect(findEq(protocolJson._domains, 'domain', targetName)).to.deep.equal({
    domain: 'test-domain',
    commands: [
      {
        'name': 'test-command'
      },
      {
        'name': 'test-command-no-conflict'
      }
    ]
  });
});

it('should throw on plugins command conflict', function() {
  var manifest = addPluginWithProtocol();
  var manifest_conflict = {
    name: 'test-plugin-conflict',
    type: 'autostart',
    protocol: {
      domains: [
        {
          domain: 'test-domain',
          commands: [
            {
              'name': 'test-command'
            }
          ]
        }
      ]
    }
  };
  plugins.validateManifest(manifest_conflict);
  plugins.getPlugins({ plugins: true }).push(manifest_conflict);

  expect(function() { return new ProtocolJson({ plugins: true }); }).to.throw(PluginError);
});

it('should correctly stringify itself', function() {
  var manifest = addPluginWithProtocol();
  var targetDomain = manifest.protocol.domains[0];
  var targetName = targetDomain.domain;
  var protocolJson = new ProtocolJson({ plugins: true });
  var json = JSON.stringify(protocolJson),
      object = JSON.parse(json);

  expect(findEq(object.domains, 'domain', targetName)).to.deep.equal(targetDomain);
});

}); });go bug

maiigirl avatar Sep 15 '18 02:09 maiigirl

Please edit the title of this issue with the name of the affected package, or "all", followed by a colon, followed by a short summary of the issue. Example: blob/gcsblob: not blobby enough.

go-cloud-bot avatar Sep 15 '18 02:09 go-cloud-bot

Hi @maiigirl , is this intended to be a bug for Go Cloud? Can you describe the bug, all I see is a bunch of Javascript code (Go Cloud is in Go, not Javascript....).

vangent avatar Sep 15 '18 03:09 vangent

@

maiigirl avatar Sep 15 '18 04:09 maiigirl

Oh well

maiigirl avatar Sep 15 '18 04:09 maiigirl