Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumana committed May 9, 2021
1 parent 78da6cc commit 9b1351d
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 5 deletions.
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.PHONY: docker-compose-up
docker-compose-up:
docker-compose up -d

.PHONY: docker-compose-down
docker-compose-down:
docker-compose down

.PHONY: setup-test-data
setup-test-data:
# project1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1.json \
http://localhost:36462/api/v1/projects
# project1 - repo1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1_repo1.json \
http://localhost:36462/api/v1/projects/project1/repos
# project1 - repo1 - content1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1_repo1_content1.json \
http://localhost:36462/api/v0/projects/project1/repositories/repo1/files/revisions/head
# project1 - repo1 - content2
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1_repo1_content2.json \
http://localhost:36462/api/v0/projects/project1/repositories/repo1/files/revisions/head
# project1 - repo2
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1_repo2.json \
http://localhost:36462/api/v1/projects/project1/repos
# project1 - repo2 - content1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project1_repo2_content1.json \
http://localhost:36462/api/v0/projects/project1/repositories/repo2/files/revisions/head
# ----------
# project2
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2.json \
http://localhost:36462/api/v1/projects
# project2 - repo1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo1.json \
http://localhost:36462/api/v1/projects/project2/repos
# project2 - repo1 - content1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo1_content1.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo1/files/revisions/head
# project2 - repo2
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2.json \
http://localhost:36462/api/v1/projects/project2/repos
# project2 - repo2 - content1
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2_content1.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo2/files/revisions/head
# project2 - repo2 - content2
curl -X POST \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2_content2.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo2/files/revisions/head

.PHONY: update-test-data
update-test-data:
curl -X PUT \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2_content2_update1.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo2/files/revisions/head
sleep 3
curl -X PUT \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2_content2_update2.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo2/files/revisions/head
sleep 3
curl -X PUT \
-H 'Authorization: Bearer anonymous' \
-H 'Content-Type: application/json' \
-d @test/data/project2_repo2_content2_update3.json \
http://localhost:36462/api/v0/projects/project2/repositories/repo2/files/revisions/head
3 changes: 3 additions & 0 deletions test/data/project1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "project1"
}
3 changes: 3 additions & 0 deletions test/data/project1_repo1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "repo1"
}
15 changes: 15 additions & 0 deletions test/data/project1_repo1_content1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test1.json",
"type": "JSON",
"path": "/test1.json",
"content": "{\"field1\": \"foo\"}"
},
"commitMessage": {
"summary": "Add /test1.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
15 changes: 15 additions & 0 deletions test/data/project1_repo1_content2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test2.json",
"type": "JSON",
"path": "/test2.json",
"content": "{\"field1\": \"bar\"}"
},
"commitMessage": {
"summary": "Add /test2.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
3 changes: 3 additions & 0 deletions test/data/project1_repo2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "repo2"
}
15 changes: 15 additions & 0 deletions test/data/project1_repo2_content1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test3.json",
"type": "JSON",
"path": "/test3.json",
"content": "{\"field1\": \"baz\"}"
},
"commitMessage": {
"summary": "Add /test3.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
3 changes: 3 additions & 0 deletions test/data/project2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "project2"
}
3 changes: 3 additions & 0 deletions test/data/project2_repo1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "repo1"
}
15 changes: 15 additions & 0 deletions test/data/project2_repo1_content1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test4.json",
"type": "JSON",
"path": "/test4.json",
"content": "{\"field1\": \"qux\"}"
},
"commitMessage": {
"summary": "Add /test4.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
3 changes: 3 additions & 0 deletions test/data/project2_repo2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "repo2"
}
15 changes: 15 additions & 0 deletions test/data/project2_repo2_content1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test5.json",
"type": "JSON",
"path": "/test5.json",
"content": "{\"field1\": \"quux\"}"
},
"commitMessage": {
"summary": "Add /test5.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
15 changes: 15 additions & 0 deletions test/data/project2_repo2_content2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"file": {
"name": "test6.json",
"type": "JSON",
"path": "/test6.json",
"content": "{\"field1\": \"corge\"}"
},
"commitMessage": {
"summary": "Add /test6.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
16 changes: 16 additions & 0 deletions test/data/project2_repo2_content2_update1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"file": {
"revision": "HEAD",
"name": "test6.json",
"type": "JSON",
"path": "/test6.json",
"content": "{\"field1\": \"corge1\"}"
},
"commitMessage": {
"summary": "Edit /test6.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
16 changes: 16 additions & 0 deletions test/data/project2_repo2_content2_update2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"file": {
"revision": "HEAD",
"name": "test6.json",
"type": "JSON",
"path": "/test6.json",
"content": "{\"field1\": \"corge2\"}"
},
"commitMessage": {
"summary": "Edit /test6.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
16 changes: 16 additions & 0 deletions test/data/project2_repo2_content2_update3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"file": {
"revision": "HEAD",
"name": "test6.json",
"type": "JSON",
"path": "/test6.json",
"content": "{\"field1\": \"corge3\"}"
},
"commitMessage": {
"summary": "Edit /test6.json",
"detail": {
"content": "",
"markup": "PLAINTEXT"
}
}
}
27 changes: 22 additions & 5 deletions test/watchService.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http2 from 'http2';
import { exec } from 'child_process';
import { CentralDogmaClient, ContentService, WatchService } from '../lib';

const { HTTP_STATUS_NOT_MODIFIED } = http2.constants;
Expand Down Expand Up @@ -47,15 +48,31 @@ describe('WatchService', () => {
});
const sut = new WatchService(client);

const project = 'project1';
const repo = 'repo1';
const filePath = '/test3.json';
const project = 'project2';
const repo = 'repo2';
const filePath = '/test6.json';

const emitter = sut.watchFile(project, repo, filePath);

let count = 0;

emitter.on('data', (data) => {
count++;
console.log(`data=${JSON.stringify(data)}`);
});

await sleep(90_000);
}, 90_000);
setTimeout(() => {
// The target updates the json three times
exec('make update-test-data', (e) => {
if (e) {
// fail
expect(true).toBe(false);
}
});
}, 1_000);

await sleep(15_000);

expect(count).toBe(3);
}, 30_000);
});

0 comments on commit 9b1351d

Please sign in to comment.