Permalink
Browse files

feat(config): branches property

  • Loading branch information...
jkuri committed Sep 2, 2017
1 parent d8a27eb commit 2d801419df11749b265c41978b40ca2219af6177
Showing with 95 additions and 1 deletion.
  1. +3 −0 docs/configuration/cache.md
  2. +26 −0 src/api/config.ts
  3. +66 −1 tests/unit/00_common.spec.ts
@@ -135,3 +135,6 @@ as they take as long to download from the cache as from the original source:
- JDK packages
- Compiled binaries
- Docker images


.... TODO
@@ -25,6 +25,7 @@ export interface Config {
os?: string;
// git: { repository_url: string, depth?: number, pr?: number, sha?: string };
cache?: { [key: string]: string }[] | null;
branches?: { test: string[], ignore: string[] };
before_install?: string[];
install: string[] | true;
before_script?: string[];
@@ -61,6 +62,7 @@ export function parseConfig(data: any): Config {
language: null,
os: null,
cache: null,
branches: null,
before_install: null,
install: null,
before_script: null,
@@ -80,6 +82,7 @@ export function parseConfig(data: any): Config {
config.language = parseLanguage(data.language || null);
config.os = parseOS(data.os || null);
config.cache = parseCache(data.cache || null);
config.branches = parseBranches(data.branches || null);

return config;
}
@@ -137,6 +140,29 @@ function parseCache(cache: any | null): { [key: string]: string }[] | null {
}
}

function parseBranches(branches: any | null): { test: string[], ignore: string[] } | null {
if (!branches) {
return null;
} else {
if (Array.isArray(branches)) {
return { test: branches, ignore: [] };
} else if (typeof branches === 'object') {
let only = [], except = [];
if (branches && branches.only) {
only = branches.only;
}

if (branches && branches.except) {
except = branches.except;
}

return { test: only, ignore: except };
} else {
throw new Error(`Unknown format for property branches.`);
}
}
}

// export function generateCommands(repositoryUrl: string, config: Config): any[] {
// let matrix = [];

@@ -5,7 +5,8 @@ let config: Config;

let data = {
language: null,
cache: null
cache: null,
branches: null
};

describe('Common Configuration Options', () => {
@@ -151,4 +152,68 @@ describe('Common Configuration Options', () => {

});

describe('Branches property', () => {
beforeEach(() => {
data = {
language: null,
cache: null,
branches: null
};
});

it(`should not throw if property is null`, () => {
expect(() => parseConfig(data)).to.not.throw(Error);
});

it(`should not throw if property is empty string`, () => {
data.branches = '';
expect(() => parseConfig(data)).to.not.throw(Error);
});

it(`should throw if property is string`, () => {
data.branches = 'master';
expect(() => parseConfig(data)).to.throw(Error);
});

it(`should not throw if property is array of branches`, () => {
data.branches = ['master', 'dev'];
expect(() => parseConfig(data)).to.not.throw(Error);
});

it(`should parse appropriate object when branches is defined as array`, () => {
data.branches = ['master', 'dev'];
const parsed = parseConfig(data);
const expected = {
test: ['master', 'dev'],
ignore: []
};
expect(parsed.branches).to.deep.equal(expected);
});

it(`should not throw error when only and except are defined with empty arrays`, () => {
data.branches = { only: [], except: [] };
expect(() => parseConfig(data)).to.not.throw(Error);
});

it(`should parse appropriate object when only and except are defined with empty arrays`, () => {
data.branches = { only: [], except: [] };
const parsed = parseConfig(data);
const expected = {
test: [],
ignore: []
};
expect(parsed.branches).to.deep.equal(expected);
});

it(`should parse appropriate object when only and except are defined with data`, () => {
data.branches = { only: ['master'], except: ['dev'] };
const parsed = parseConfig(data);
const expected = {
test: ['master'],
ignore: ['dev']
};
expect(parsed.branches).to.deep.equal(expected);
});
});

});

0 comments on commit 2d80141

Please sign in to comment.