forked from Joxit/docker-registry-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(branching): start new configurable branching repository system
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const getRepositoryName = (split, max) => { | ||
let repositoryName = ''; | ||
for (let i = 0; i < max; i++) { | ||
repositoryName += `${split[i]}/`; | ||
} | ||
return repositoryName; | ||
}; | ||
|
||
export const getBranching = | ||
(min = 1, max = 1) => | ||
(repositories) => | ||
repositories.sort().reduce(function (acc, image) { | ||
const split = image.split('/'); | ||
if (split.length > min && min > 0) { | ||
const repoName = getRepositoryName(split, max); | ||
if (acc.length === 0 || acc[acc.length - 1].repo != repoName) { | ||
acc.push({ | ||
repo: repoName, | ||
images: [], | ||
}); | ||
} | ||
acc[acc.length - 1].images.push(image); | ||
return acc; | ||
} | ||
acc.push(image); | ||
return acc; | ||
}, []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getBranching } from '../src/scripts/repositories.js'; | ||
import assert from 'assert'; | ||
|
||
describe('repositories', () => { | ||
describe('getBranching', () => { | ||
it('should not branch for no levels', () => { | ||
const branching = getBranching(0, 0); | ||
assert.deepEqual(branching(['alpine', 'debian', 'nginx']), ['alpine', 'debian', 'nginx']); | ||
assert.deepEqual(branching(['alpine', 'joxit/docker-registry-ui', 'nginx']), [ | ||
'alpine', | ||
'joxit/docker-registry-ui', | ||
'nginx', | ||
]); | ||
}); | ||
|
||
it('should branch for one level', () => { | ||
const branching = getBranching(1, 1); | ||
assert.deepEqual(branching(['alpine', 'debian', 'nginx']), ['alpine', 'debian', 'nginx']); | ||
assert.deepEqual(branching(['alpine', 'joxit/docker-registry-ui', 'nginx']), [ | ||
'alpine', | ||
{ images: ['joxit/docker-registry-ui'], repo: 'joxit/' }, | ||
'nginx', | ||
]); | ||
assert.deepEqual(branching(['alpine', 'joxit/docker-registry-ui', 'joxit/kokai', 'nginx']), [ | ||
'alpine', | ||
{ images: ['joxit/docker-registry-ui', 'joxit/kokai'], repo: 'joxit/' }, | ||
'nginx', | ||
]); | ||
}); | ||
}); | ||
}); |