Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit bedd159

Browse files
Atualização geral de arquivos de testes de componentes, helper e scripts de execução;
1 parent 502aa03 commit bedd159

File tree

24 files changed

+480
-122
lines changed

24 files changed

+480
-122
lines changed

examples/lambda_api/flambda_app/helper.py

+10
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,13 @@ def get_function_name(class_name=""):
255255
if not class_name:
256256
fn_name = traceback.extract_stack(None, 2)[0][2]
257257
return fn_name
258+
259+
260+
def convert_list_to_dict(item_list, key_name):
261+
result = dict()
262+
if isinstance(item_list, list):
263+
for item in item_list:
264+
if isinstance(item, dict) and key_name in item.keys():
265+
result[item.get(key_name)] = item
266+
267+
return result
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/migrations/mysql/migrate.py; then
47+
echo '----------------------------------------'
48+
echo 'Booting database...'
49+
echo '----------------------------------------'
50+
# TODO futuramente usar o Flask migrate ou outra alternativa
51+
echo 'Creating tables...'
52+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.products.sql
53+
54+
read -p "Press enter to continue..."
55+
56+
echo 'Inserting data in the table...'
57+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
58+
fi
59+
60+

examples/lambda_api/scripts/preenv.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# pre requirements for ELK
3+
#sudo sysctl -w -q vm.max_map_count=262144
4+
#sudo sysctl -w -q fs.file-max=65536
5+
#ulimit -n 65536
6+
#ulimit -u 4096
7+
#ulimit -c unlimited

examples/lambda_api/scripts/runenv.sh

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22
export TEST_ENV=0
3+
if test -f ./scripts/preenv.sh; then
4+
source ./scripts/preenv.sh;
5+
else
6+
echo './scripts/preenv.sh not found'
7+
fi
38
docker-compose up $1 $2 $3
+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22
export TEST_ENV=1
3+
if test -f ./scripts/preenv.sh; then
4+
source ./scripts/preenv.sh;
5+
else
6+
echo './scripts/preenv.sh not found'
7+
fi
38
docker-compose up $1 $2 $3

examples/lambda_api/tests/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Tests
2+
Descrição da estrutura da pasta e conceitos
3+
4+
## Testes de unidade
5+
* Testes que se utiliza de mocks para evitar conexões reais a componetes externos;
6+
* Testes focados na funcionalidade e não nos dados em si;
7+
* Testes para serem executados em pipelines de CI;
8+
* A duração destes testes devem ser de no máximo 1s por arquivo, sendo o ideal rodar em milisegundos;
9+
10+
## Testes de integração
11+
* Testes que não devem executar fixtures ou alterações de recursos para evitar problemas;
12+
* Testes focados na integração de componentes externos com a aplicação em questão;
13+
* Testes para serem executados em pipelines de CD;
14+
* A duração destes vai depender dos cenários desenvolvidos, porém recomendado criar testes objetivos para não demorar muito o pipeline;
15+
16+
## Testes de componentes
17+
* Testes bases para o processo de TDD;
18+
* Testes focados no comportamento, cenários e dados dos processo do projeto;
19+
* Testes para serem executados localmente em conjunto do docker que irá prover o acesso local a recursos como banco de dados e afins;
20+
* A duração destes vai depender dos cenários desenvolvidos, mas a ideia destes testes é explorar diversos cenários possíveis;
21+
22+
## Referências
23+
* https://martinfowler.com/articles/microservice-testing/

examples/lambda_api/tests/component/test_app.py

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import json
66
import os
7+
import time
78
import unittest
89

910
import serverless_wsgi
@@ -16,14 +17,21 @@
1617
from tests.component.componenttestutils import BaseComponentTestCase
1718
from tests.component.helpers.aws.sqs_helper import SQSHelper
1819
from tests.component.helpers.database.mysql_helper import MySQLHelper
20+
from tests.unit.helpers.events_helper import get_cancelamento_event
1921
from tests.unit.mocks.aws_mocks.aws_lambda_mock import FakeLambdaContext
2022
from tests.unit.mocks.lambda_event_mocks.request_event import create_aws_api_gateway_proxy_request_event
2123
from tests.unit.testutils import get_function_name
2224

2325

2426
def get_queue_message():
2527
queue_url = os.getenv("APP_QUEUE")
28+
29+
message = get_cancelamento_event()
30+
SQSHelper.create_message(message, queue_url)
31+
time.sleep(1)
32+
2633
event = SQSHelper.get_message(queue_url)
34+
2735
return (event,)
2836

2937

examples/lambda_api_restful/flambda_app/helper.py

+10
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,13 @@ def get_function_name(class_name=""):
255255
if not class_name:
256256
fn_name = traceback.extract_stack(None, 2)[0][2]
257257
return fn_name
258+
259+
260+
def convert_list_to_dict(item_list, key_name):
261+
result = dict()
262+
if isinstance(item_list, list):
263+
for item in item_list:
264+
if isinstance(item, dict) and key_name in item.keys():
265+
result[item.get(key_name)] = item
266+
267+
return result

examples/lambda_api_restful/lambda_app/database/dynamodb.py

-61
This file was deleted.

examples/lambda_api_restful/lambda_app/logging.py

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,60 @@
11
#!/bin/bash
2-
#echo 'Booting database...'
3-
## TODO futuramente usar o Flask migrate ou outra alternativa
4-
#
5-
#echo 'Creating tables...'
6-
python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/structure/mysql/create.table.store.products.sql
7-
#
8-
#echo 'Inserting data in the table...'
9-
python3 ./scripts/migrations/mysql/migrate.py ./tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/migrations/mysql/migrate.py; then
47+
echo '----------------------------------------'
48+
echo 'Booting database...'
49+
echo '----------------------------------------'
50+
# TODO futuramente usar o Flask migrate ou outra alternativa
51+
echo 'Creating tables...'
52+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.products.sql
53+
54+
read -p "Press enter to continue..."
55+
56+
echo 'Inserting data in the table...'
57+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
58+
fi
59+
60+
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22
export TEST_ENV=0
3+
if test -f ./scripts/preenv.sh; then
4+
source ./scripts/preenv.sh;
5+
else
6+
echo './scripts/preenv.sh not found'
7+
fi
38
docker-compose up $1 $2 $3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/bash
22
export TEST_ENV=1
3+
if test -f ./scripts/preenv.sh; then
4+
source ./scripts/preenv.sh;
5+
else
6+
echo './scripts/preenv.sh not found'
7+
fi
38
docker-compose up $1 $2 $3

0 commit comments

Comments
 (0)