Skip to content

Commit

Permalink
add test case for savePropertiesFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jtfell committed Feb 9, 2018
1 parent f5f29fa commit 5685991
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/properties-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import yaml from 'js-yaml';
*
* @return {Object} properties
*/
export default function loadPropertiesFile(path) {
export function loadPropertiesFile(path) {
let doc;
try {
const contents = fs.readFileSync(path, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import rc from 'rc';
import fs from 'fs';
import gitRemoteOriginUrl from 'git-remote-origin-url';
import getUrlFromGitRemote from './git';
import loadPropertiesFile from './properties-file';
import { loadPropertiesFile } from './properties-file';

const gitlabEnvFileName = 'gitlab.env.yml';

Expand Down
28 changes: 27 additions & 1 deletion test/lib/properties-file.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import loadPropertiesFile from '../../src/lib/properties-file';
import { loadPropertiesFile, savePropertiesFile } from '../../src/lib/properties-file';
import { readFileSync, unlinkSync } from 'fs';

const cwd = process.cwd();

Expand All @@ -14,4 +15,29 @@ describe('properties-file-handler', () => {
expect(properties.NPM_INSTALL_TOKEN).to.equal(123456789);
});
});

context('savePropertiesFile', () => {
it('saves properties object into properties file', () => {
const path = `${cwd}/test/fixtures/test-save.yml`;
savePropertiesFile(path, [
{
key: 'TEST_KEY',
value: 'hello',
protected: false,
},
{
key: 'TOKEN',
value: 'jkdsjkldfsjkl',
protected: false,
}
]);

const result = readFileSync(path, 'utf8');
expect(result).to.equal(`TEST_KEY: hello
TOKEN: jkdsjkldfsjkl
`);

unlinkSync(path);
});
});
});

0 comments on commit 5685991

Please sign in to comment.