Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test folder creation via processDirectoryStructure() #4

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@simplyhexagonal/exec": "2.0.2",
"@simplyhexagonal/logger": "2.1.1",
"@simplyhexagonal/mono-context": "1.1.2",
"@types/yargs": "^17.0.10",
"dotenv": "16.0.1",
"fs-extra": "10.1.0",
"ora": "6.1.1",
Expand Down
62 changes: 42 additions & 20 deletions pnpm-lock.yaml

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

6 changes: 4 additions & 2 deletions src/fixtures/project-structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
{
"name": "content-from-s3",
"flags": ["must-store"],
"flags": ["must-skip"],
"contentSources": [
{
"sourcePath": "s3://static.xtld.stream/content-samples",
Expand All @@ -86,6 +86,7 @@
},
{
"name": "content-from-tar",
"flags": [ "must-skip" ],
"contentSources": [
{
"sourcePath": "./content-from-s3/archive/tape-archive/text-files-and-sub-dir.tar",
Expand All @@ -95,7 +96,7 @@
},
{
"name": "content-from-tgz",
"flags": ["must-store"],
"flags": [ "must-skip" ],
"contentSources": [
{
"sourcePath": "./content-from-s3/archive/tape-archive-gunzip/text-files-and-sub-dir.tgz",
Expand All @@ -105,6 +106,7 @@
},
{
"name": "content-from-zip",
"flags": [ "must-skip" ],
"contentSources": [
{
"sourcePath": "./content-from-s3/archive/compressed-files/document-and-video.zip",
Expand Down
46 changes: 45 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from "fs";
import {
ensureDirSync,
copyFileSync,
Expand All @@ -9,7 +10,7 @@ import Logger from '@simplyhexagonal/logger';
import projectStructure from './fixtures/project-structure.json';

import { processDirectoryStructure } from './';
import { DirectoryStructure } from './interfaces';
import { DirectoryStructure, ContentSource } from './interfaces';

beforeAll(() => {
ensureDirSync('/tmp/make-dir-structure');
Expand All @@ -36,4 +37,47 @@ describe('index', () => {

expect(true).toBe(true);
});

it('creates a single /empty-dir inside /testfiles', async () => {
// ARRANGE
const emptyDirStructure = projectStructure.directoryStructure.filter((directory) => directory["name"] === "empty-dir") as DirectoryStructure
// const emptyDirStructure = projectStructure.directoryStructure.filter((directory) => directory["directories"] === undefined || directory["directories"] === []) as DirectoryStructure

// ACT
const result = await processDirectoryStructure(
{
rootWorkingDirectory: './testfiles',
directoryStructure: emptyDirStructure,
}
);

// ASSERT
console.log(result);
expect(result[0].success).toBe(true);
});

it('creates /testfiles/content-dir/content-from-ftp and downloads its content', async () => {
// ARRANGE
const contentDirStructure = projectStructure.directoryStructure.filter((directory) => directory["name"] === "content-dir") as DirectoryStructure
const contentFromFTPDirStructure = contentDirStructure[0]["directories"]!.filter((subdirectory) => subdirectory["name"] === "content-from-ftp") as DirectoryStructure
const contentSources = contentFromFTPDirStructure[0]["contentSources"]![0] as ContentSource
const storageDirectory = "testfiles/content-dir/content-from-ftp";

// ACT
const result = await processDirectoryStructure(
{
rootWorkingDirectory: './testfiles/content-dir',
directoryStructure: contentFromFTPDirStructure,
}
);

// ASSERT
let files = fs.readdirSync(`${storageDirectory}/repodata`);
console.log(files);
expect(files.length).toBeGreaterThan(0); // Expect folder to be populated

console.log(result);
result.map(item => expect(item.success).toBe(true));
expect(contentSources["sourcePath"]).toBe("ftp://ubuntu.osuosl.org/pub/elrepo/extras/el9/SRPMS")
});
});
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { resolve } from 'path';
import { hideBin } from 'yargs/helpers';
import MonoContext from '@simplyhexagonal/mono-context';import yargs from 'yargs';
import MonoContext from '@simplyhexagonal/mono-context';
import yargs from 'yargs';
import Logger from '@simplyhexagonal/logger';

import { commands } from './commands';
Expand Down