Skip to content

Commit

Permalink
Merge pull request #23 from adamjosefus/feature/access-token-support
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
adamjosefus authored Feb 22, 2022
2 parents d1e1b40 + f9db6d4 commit 45c4d62
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
pkg.macos
pkg.exe
pkg.linux
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ deno run pkg.ts --help
"from": "<path-to-file>"
}
}, // optional
"packages": {
"repositories": {
"<repo-reference>": {
"destination": "<path-to-dir>" // optional
"name": "<name>" // optional
Expand All @@ -92,7 +92,7 @@ deno run pkg.ts --help
"from": "./sercet.txt"
}
},
"packages": {
"repositories": {
"https://github.com/foo.git": [
{
"name": "Foo_v1",
Expand Down
1 change: 0 additions & 1 deletion demo/bar.token

This file was deleted.

18 changes: 0 additions & 18 deletions demo/config.json

This file was deleted.

2 changes: 0 additions & 2 deletions demo/demo.sh

This file was deleted.

2 changes: 0 additions & 2 deletions demo/packages/.gitignore

This file was deleted.

10 changes: 5 additions & 5 deletions libs/model/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ export function parseConfig(json: string, configRoot: string, separateGitRoot: s
const config: ConfigType = [];
const data = JSON.parse(json) as ConfigSchema;
const commonVars = crateVariables(configRoot, data.variables ?? {});
const packages = data.packages ?? {};
const repositories = data.repositories ?? {};

for (const reference in packages) {
for (const reference in repositories) {
// Normalize reference
const settingsArr = (v => {
if (v === true || v === null) return [{}];
if (v === false) return null;
if (v === false || v === null) return null;
if (v === true) return [{}];

return Array.isArray(v) ? v : [v];
})(packages[reference]);
})(repositories[reference]);

// Skip if no settings
if (settingsArr === null) break;
Expand Down
2 changes: 0 additions & 2 deletions libs/model/variableFilters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

export const variableFilters: Map<string, (s: string) => string> = new Map();

variableFilters.set("encodeUri", (s: string) => encodeURI(s));

variableFilters.set("encodeUriComponent", (s: string) => encodeURIComponent(s));
2 changes: 1 addition & 1 deletion libs/types/ConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ type PackageMapType = Record<string, PackageType | PackageType[] | boolean | nul
export type ConfigSchema = {
destination?: string,
variables?: VariableDeclarationsType,
packages?: PackageMapType,
repositories?: PackageMapType,
};
148 changes: 148 additions & 0 deletions tests/parseConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { parseConfig } from "../libs/model/parseConfig.ts";


Deno.test("parseConfig", () => {
const configRoot = '/packages';
const separateGitRoot = '/meta';


const exercises: {
label: string,
json: string,
expected: unknown,
}[] = [
{
label: "Test 1",
json: `{}`,
expected: [],
},
{
label: "Test 2",
json: `{
"repositories": {
"https://github.com/my-repo.git": {
}
}
}`,
expected: [
{
destinationDir: "/packages/my-repo",
displayReference: "https://github.com/my-repo.git",
name: "my-repo",
reference: "https://github.com/my-repo.git",
separatedGitDir: "/meta/my-repo",
tag: null,
},
],
},
{
label: "Test 3",
json: `{
"repositories": {
"https://github.com/my-repo.git": false
}
}`,
expected: [],
},
{
label: "Test 4",
json: `{
"repositories": {
"https://github.com/my-repo.git": null
}
}`,
expected: [],
},
{
label: "Test 5",
json: `{
"repositories": {
"https://github.com/my-repo.git": true
}
}`,
expected: [
{
destinationDir: "/packages/my-repo",
displayReference: "https://github.com/my-repo.git",
name: "my-repo",
reference: "https://github.com/my-repo.git",
separatedGitDir: "/meta/my-repo",
tag: null,
},
],
},
{
label: "Test 6",
json: `{
"destination": "./subdir",
"repositories": {
"https://github.com/my-repo.git": true
}
}`,
expected: [
{
destinationDir: "/packages/subdir/my-repo",
displayReference: "https://github.com/my-repo.git",
name: "my-repo",
reference: "https://github.com/my-repo.git",
separatedGitDir: "/meta/my-repo",
tag: null,
},
],
},
{
label: "Test 7",
json: `{
"destination": "./subdir",
"repositories": {
"https://github.com/my-repo.git": {
"destination": "./subdir2"
}
}
}`,
expected: [
{
destinationDir: "/packages/subdir2/my-repo",
displayReference: "https://github.com/my-repo.git",
name: "my-repo",
reference: "https://github.com/my-repo.git",
separatedGitDir: "/meta/my-repo",
tag: null,
},
],
},
{
label: "Test 8",
json: `{
"destination": "./subdir",
"variables": {
"MY_VAR": "my-value"
},
"repositories": {
"https://github.com/my-repo.git": {
"destination": "./subdir2/${"${MY_VAR}"}"
}
}
}`,
expected: [
{
destinationDir: "/packages/subdir2/my-value/my-repo",
displayReference: "https://github.com/my-repo.git",
name: "my-repo",
reference: "https://github.com/my-repo.git",
separatedGitDir: "/meta/my-repo",
tag: null,
},
],
},
];


exercises.forEach(({ json, expected, label }) => {
const config = parseConfig(json, configRoot, separateGitRoot);

assertEquals(config, expected, label);
});
});

0 comments on commit 45c4d62

Please sign in to comment.