Skip to content

Commit

Permalink
Fix multiple distros sorting in meta/mail.yaml (#37)
Browse files Browse the repository at this point in the history
* Fix distros grouping in meta/main.yml

* 0.3.1
  • Loading branch information
coaxial committed Oct 6, 2018
1 parent aa1a9f1 commit cb0fc91
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 15 deletions.
35 changes: 35 additions & 0 deletions __tests__/__snapshots__/app.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand Down Expand Up @@ -264,6 +269,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand All @@ -288,6 +298,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags: []
dependencies:
Expand Down Expand Up @@ -353,6 +368,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand Down Expand Up @@ -426,6 +446,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand Down Expand Up @@ -499,6 +524,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand Down Expand Up @@ -574,6 +604,11 @@ galaxy_info:
- trusty
- xenial
- bionic
- name: debian
versions:
- stretch
- jessie
galaxy_tags:
- test
- system
Expand Down
20 changes: 20 additions & 0 deletions __tests__/__snapshots__/helpers.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,23 @@ Array [
},
]
`;

exports[`helpers #platformsToMetaMain formats the list correctly 1`] = `
Array [
Object {
"name": "ubuntu",
"versions": Array [
"trusty",
"xenial",
"bionic",
],
},
Object {
"name": "debian",
"versions": Array [
"jessie",
"stretch",
],
},
]
`;
14 changes: 14 additions & 0 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe('generator-molecule-lxd-role:app', () => {
versionNumber: '14.04',
tags: ['lts', 'current'],
},
{
family: 'debian',
distribution: 'debian',
codeName: 'stretch',
versionNumber: '9',
tags: ['lts'],
},
{
family: 'debian',
distribution: 'debian',
codeName: 'jessie',
versionNumber: '8',
tags: ['current'],
},
{
family: 'debian',
distribution: 'ubuntu',
Expand Down
50 changes: 49 additions & 1 deletion __tests__/helpers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict';
const { safeDump } = require('js-yaml');

const assert = require('yeoman-assert');

const { PLATFORMS } = require('../generators/constants');
const { safeDump } = require('js-yaml');
const {
capitalize,
indent,
listPlatforms,
listVersions,
moleculePlatforms,
parseDeps,
platformsToMetaMain,
} = require('../generators/helpers');

describe('helpers', () => {
Expand All @@ -31,6 +33,52 @@ describe('helpers', () => {
});
});

describe('#platformsToMetaMain', () => {
it('formats the list correctly', () => {
const versions = [
{
family: 'debian',
distribution: 'ubuntu',
codeName: 'trusty',
versionNumber: '14.04',
tags: ['lts', 'current'],
},
{
family: 'debian',
distribution: 'ubuntu',
codeName: 'xenial',
versionNumber: '16.04',
tags: ['lts', 'current'],
},
{
family: 'debian',
distribution: 'ubuntu',
codeName: 'bionic',
versionNumber: '18.04',
tags: ['lts', 'current'],
},
{
family: 'debian',
distribution: 'debian',
codeName: 'jessie',
versionNumber: '8',
tags: ['current'],
},
{
family: 'debian',
distribution: 'debian',
codeName: 'stretch',
versionNumber: '9',
tags: ['lts'],
},
];

const actual = platformsToMetaMain(versions);

expect(actual).toMatchSnapshot();
});
});

describe('#moleculePlatforms', () => {
it('formats the list correctly', () => {
const versions = [
Expand Down
5 changes: 2 additions & 3 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mkdirp = require('mkdirp');

const path = require('path');

const { indentYaml, parseDeps } = require('../helpers');
const { indentYaml, parseDeps, platformsToMetaMain } = require('../helpers');
const prompts = require('./prompts');

module.exports = class extends Generator {
Expand Down Expand Up @@ -95,11 +95,10 @@ module.exports = class extends Generator {
hasDeps: p.hasDeps,
license: p.license,
minAnsibleVer: p.minAnsibleVer,
platforms: p.supportedPlatforms,
roleDeps: parseDeps(p.roleDeps),
roleDesc: p.roleDesc,
roleName: paramCase(p.roleName),
targetVersions: p.targetVersions,
targetVersions: indentYaml(4, platformsToMetaMain(p.targetVersions)),
},
);

Expand Down
8 changes: 1 addition & 7 deletions generators/app/templates/meta_main.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ galaxy_info:
license: <%- license %>
min_ansible_version: <%- minAnsibleVer %>
platforms:
<% targetVersions.forEach((v, index) => { -%>
<% if(index === 0) { -%>
- name: <%- v.distribution %>
versions:
<% } -%>
- <%- v.codeName %>
<% }) -%>
<%- targetVersions %>
<%- galaxyTags %>
<% if(hasDeps) { -%>
dependencies:
Expand Down
23 changes: 23 additions & 0 deletions generators/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
const { Separator } = require('inquirer');
const {
append,
compose,
concat,
curry,
either,
findIndex,
head,
insert,
isEmpty,
Expand All @@ -15,6 +17,8 @@ const {
map,
pipe,
prop,
propEq,
reduce,
repeat,
replace,
tail,
Expand Down Expand Up @@ -125,6 +129,24 @@ const indentYaml = curry((count, yaml) =>
)(yaml),
);

const platformsToMetaMain = platforms =>
reduce(
(acc, p) => {
const index = findIndex(propEq('name', p.distribution), acc);

if (index >= 0) {
// Acc already knows of that distro, we add codeName to the existing list
acc[index].versions = append(p.codeName, acc[index].versions);
} else {
// Create the version and add the codeName
acc = append({ name: p.distribution, versions: [p.codeName] }, acc);
}
return acc;
},
[],
platforms,
);

module.exports = {
listPlatforms,
capitalize,
Expand All @@ -133,4 +155,5 @@ module.exports = {
moleculePlatforms,
indent,
indentYaml,
platformsToMetaMain,
};
4 changes: 2 additions & 2 deletions generators/molecule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ module.exports = class extends Generator {
);

// When testing a playbook, the converge playbook is the playbook under
// but when testing a role, a default converge playbook running the role is
// needed
// test but when testing a role, a default converge playbook running the
// role is needed
if (this.options.mode === 'role') {
this.fs.copyTpl(
this.templatePath('playbook.yml.ejs'),
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-molecule-lxd-role",
"version": "0.3.0",
"version": "0.3.1",
"description": "Ansible role testing with molecule using LXD containers with optional Travis CI integration",
"homepage": "",
"author": {
Expand Down

0 comments on commit cb0fc91

Please sign in to comment.