Skip to content

Commit 40eb5c5

Browse files
committed
Added read-write unit-test
1 parent 3e54cae commit 40eb5c5

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tmp/*
55
.wsjcpp-cache/*
66
.wsjcpp-logs/*
77
.wsjcpp/*
8+
unit-tests.wsjcpp/data-tests/read-write-file/docker-compose.output.yml
89

910
# Prerequisites
1011
*.d

unit-tests.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_remove_element_f
4646
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_remove_element_in_array.cpp")
4747
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_memory_leaks.cpp")
4848
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_read_yaml.cpp")
49+
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_read_write_file.cpp")
4950

5051
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.user-custom.txt)
5152

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# https://github.com/dockersamples/example-voting-app/blob/master/docker-compose.yml
2+
3+
version: "3"
4+
5+
services:
6+
vote:
7+
build: ./vote
8+
command: python app.py
9+
volumes:
10+
- ./vote:/app
11+
ports:
12+
- "5000:80"
13+
networks:
14+
- front-tier
15+
- back-tier
16+
17+
result:
18+
build: ./result
19+
command: nodemon server.js
20+
volumes:
21+
- ./result:/app
22+
ports:
23+
- "5001:80"
24+
- "5858:5858"
25+
networks:
26+
- front-tier
27+
- back-tier
28+
29+
worker:
30+
build:
31+
context: ./worker
32+
depends_on:
33+
- "redis"
34+
- "db"
35+
networks:
36+
- back-tier
37+
38+
redis:
39+
image: redis:alpine
40+
container_name: redis
41+
ports: ["6379"]
42+
networks:
43+
- back-tier
44+
45+
db:
46+
image: postgres:9.4
47+
container_name: db
48+
environment:
49+
POSTGRES_USER: "postgres"
50+
POSTGRES_PASSWORD: "postgres"
51+
volumes:
52+
- "db-data:/var/lib/postgresql/data"
53+
networks:
54+
- back-tier
55+
56+
volumes:
57+
db-data:
58+
59+
networks:
60+
front-tier:
61+
back-tier:
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
#include <wsjcpp_core.h>
3+
#include <wsjcpp_unit_tests.h>
4+
#include <wsjcpp_yaml.h>
5+
6+
// ---------------------------------------------------------------------
7+
// UnitTestReadWriteFile
8+
9+
class UnitTestReadWriteFile : public WsjcppUnitTestBase {
10+
public:
11+
UnitTestReadWriteFile();
12+
virtual bool doBeforeTest() override;
13+
virtual void executeTest() override;
14+
virtual bool doAfterTest() override;
15+
};
16+
17+
REGISTRY_WSJCPP_UNIT_TEST(UnitTestReadWriteFile)
18+
19+
UnitTestReadWriteFile::UnitTestReadWriteFile()
20+
: WsjcppUnitTestBase("UnitTestReadWriteFile") {
21+
}
22+
23+
// ---------------------------------------------------------------------
24+
25+
bool UnitTestReadWriteFile::doBeforeTest() {
26+
// do something before test
27+
return true;
28+
}
29+
30+
// ---------------------------------------------------------------------
31+
32+
void UnitTestReadWriteFile::executeTest() {
33+
WsjcppYaml yaml;
34+
std::string sFilepath = "./data-tests/read-write-file/docker-compose.yml";
35+
std::string sFilepathOutput = "./data-tests/read-write-file/docker-compose.output.yml";
36+
std::string sError;
37+
if (!compare("Error parsing", yaml.loadFromFile(sFilepath, sError), true)) {
38+
WsjcppLog::err(TAG, sError);
39+
return;
40+
}
41+
42+
compare("has version", yaml.getRoot()->hasElement("version"), true);
43+
compare("has volumes", yaml.getRoot()->hasElement("volumes"), true);
44+
compare("has networks", yaml.getRoot()->hasElement("networks"), true);
45+
compare("has services", yaml.getRoot()->hasElement("services"), true);
46+
47+
compare("version-value", yaml.getRoot()->getElement("version")->getStringValue(), "3");
48+
compare("version-value", yaml.getRoot()->getElement("version")->getIntValue(), 3); // wrong or not ?
49+
50+
if (!compare("Error parsing", yaml.saveToFile(sFilepathOutput), true)) {
51+
WsjcppLog::err(TAG, sError);
52+
return;
53+
}
54+
55+
std::string sOriginalFileContent;
56+
WsjcppCore::readTextFile(sFilepath, sOriginalFileContent);
57+
std::string sOutputFileContent;
58+
WsjcppCore::readTextFile(sFilepathOutput, sOutputFileContent);
59+
60+
compare("compare conteent ", sOutputFileContent, sOriginalFileContent);
61+
62+
}
63+
64+
// ---------------------------------------------------------------------
65+
66+
bool UnitTestReadWriteFile::doAfterTest() {
67+
// do somethig after test
68+
return true;
69+
}
70+
71+

wsjcpp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ unit-tests:
5959
description: ""
6060
- name: "ReadYaml"
6161
description: ""
62+
- name: "ReadWriteFile"
63+
description: ""

0 commit comments

Comments
 (0)