bonsaif 1.10.39 β 1.10.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -133
- package/lib/execute.js +0 -28
- package/lib/hookup/exec.js +2 -4
- package/lib/hookup/mariadb.js +10 -28
- package/lib/hookup/mongodb.js +177 -193
- package/lib/hookup/postgres.js +27 -35
- package/lib/hookup/redis.js +42 -162
- package/package.json +3 -6
- package/lib/hookup/mongoose.js +0 -988
- package/tests/README.md +0 -245
- package/tests/config.example.js +0 -61
- package/tests/docker-restart.sh +0 -20
- package/tests/docker-start.sh +0 -192
- package/tests/docker-stop.sh +0 -41
- package/tests/run-all-tests.js +0 -76
- package/tests/test-mariadb.js +0 -85
- package/tests/test-mongodb.js +0 -133
- package/tests/test-mongoose.js +0 -408
- package/tests/test-postgres.js +0 -84
- package/tests/test-redis.js +0 -85
package/tests/README.md
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
# Pruebas de Conexiones Bonsaif
|
|
2
|
-
|
|
3
|
-
Carpeta con pruebas estΓ‘ndar para validar el correcto funcionamiento de las conexiones a bases de datos.
|
|
4
|
-
|
|
5
|
-
## π Requisitos Previos
|
|
6
|
-
|
|
7
|
-
### OpciΓ³n 1: Docker (Recomendado - RΓ‘pido)
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# Iniciar todos los servicios
|
|
11
|
-
cd tests
|
|
12
|
-
./docker-start.sh
|
|
13
|
-
|
|
14
|
-
# Detener todos los servicios
|
|
15
|
-
./docker-stop.sh
|
|
16
|
-
|
|
17
|
-
# Reiniciar todos los servicios
|
|
18
|
-
./docker-restart.sh
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
El script automΓ‘ticamente:
|
|
22
|
-
- β Levanta Redis en puerto 6379
|
|
23
|
-
- β Levanta MongoDB en puerto 27017
|
|
24
|
-
- β Levanta MariaDB en puerto 3306 (con base de datos y tabla)
|
|
25
|
-
- β Levanta PostgreSQL en puerto 5432 (con base de datos y tabla)
|
|
26
|
-
|
|
27
|
-
### OpciΓ³n 2: InstalaciΓ³n Manual
|
|
28
|
-
|
|
29
|
-
#### Redis
|
|
30
|
-
```bash
|
|
31
|
-
# Docker
|
|
32
|
-
docker run -d -p 6379:6379 redis:latest
|
|
33
|
-
|
|
34
|
-
# Homebrew (macOS)
|
|
35
|
-
brew install redis
|
|
36
|
-
redis-server
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
#### MongoDB
|
|
40
|
-
```bash
|
|
41
|
-
# Docker
|
|
42
|
-
docker run -d -p 27017:27017 mongo:latest
|
|
43
|
-
|
|
44
|
-
# Homebrew (macOS)
|
|
45
|
-
brew tap mongodb/brew
|
|
46
|
-
brew install mongodb-community
|
|
47
|
-
mongod --config /usr/local/etc/mongod.conf
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
#### MariaDB/MySQL
|
|
51
|
-
```bash
|
|
52
|
-
# Docker
|
|
53
|
-
docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mariadb:latest
|
|
54
|
-
|
|
55
|
-
# Homebrew (macOS)
|
|
56
|
-
brew install mariadb
|
|
57
|
-
mysql.server start
|
|
58
|
-
|
|
59
|
-
# Crear tabla de prueba
|
|
60
|
-
mysql -u root
|
|
61
|
-
CREATE DATABASE IF NOT EXISTS test;
|
|
62
|
-
USE test;
|
|
63
|
-
CREATE TABLE IF NOT EXISTS test_users (
|
|
64
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
65
|
-
name VARCHAR(100),
|
|
66
|
-
email VARCHAR(100),
|
|
67
|
-
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
68
|
-
);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
#### PostgreSQL
|
|
72
|
-
```bash
|
|
73
|
-
# Docker
|
|
74
|
-
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:latest
|
|
75
|
-
|
|
76
|
-
# Homebrew (macOS)
|
|
77
|
-
brew install postgresql
|
|
78
|
-
brew services start postgresql
|
|
79
|
-
|
|
80
|
-
# Crear tabla de prueba
|
|
81
|
-
psql -U postgres
|
|
82
|
-
CREATE DATABASE test;
|
|
83
|
-
\c test
|
|
84
|
-
CREATE TABLE IF NOT EXISTS test_users (
|
|
85
|
-
id SERIAL PRIMARY KEY,
|
|
86
|
-
name VARCHAR(100),
|
|
87
|
-
email VARCHAR(100),
|
|
88
|
-
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
89
|
-
);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## βοΈ ConfiguraciΓ³n
|
|
93
|
-
|
|
94
|
-
1. Copiar el archivo de ejemplo:
|
|
95
|
-
```bash
|
|
96
|
-
cp tests/config.example.js tests/config.js
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
2. Editar `tests/config.js` con tus credenciales locales
|
|
100
|
-
|
|
101
|
-
## π Ejecutar Pruebas
|
|
102
|
-
|
|
103
|
-
### Pruebas Individuales
|
|
104
|
-
```bash
|
|
105
|
-
# Redis
|
|
106
|
-
node tests/test-redis.js
|
|
107
|
-
|
|
108
|
-
# MongoDB
|
|
109
|
-
node tests/test-mongodb.js
|
|
110
|
-
|
|
111
|
-
# Mongoose (ORM para MongoDB)
|
|
112
|
-
node tests/test-mongoose.js
|
|
113
|
-
|
|
114
|
-
# MariaDB
|
|
115
|
-
node tests/test-mariadb.js
|
|
116
|
-
|
|
117
|
-
# PostgreSQL
|
|
118
|
-
node tests/test-postgres.js
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Todas las Pruebas
|
|
122
|
-
```bash
|
|
123
|
-
node tests/run-all-tests.js
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## π Estructura de Pruebas
|
|
127
|
-
|
|
128
|
-
Cada archivo de prueba valida:
|
|
129
|
-
|
|
130
|
-
### Redis
|
|
131
|
-
- β SET (con expiraciΓ³n)
|
|
132
|
-
- β GET
|
|
133
|
-
- β SCAN
|
|
134
|
-
- β SADD / SMEMBERS
|
|
135
|
-
- β HSET / HGETALL
|
|
136
|
-
- β DBSIZE
|
|
137
|
-
- β KEYS
|
|
138
|
-
- β DEL
|
|
139
|
-
|
|
140
|
-
### MongoDB
|
|
141
|
-
- β INSERT
|
|
142
|
-
- β FIND
|
|
143
|
-
- β UPDATE
|
|
144
|
-
- β COUNT
|
|
145
|
-
- β COMMAND
|
|
146
|
-
- β UPSERT
|
|
147
|
-
- β DBS
|
|
148
|
-
- β COLLECTIONS
|
|
149
|
-
- β DELETEMANY
|
|
150
|
-
|
|
151
|
-
### Mongoose (ORM para MongoDB)
|
|
152
|
-
- β INSERT (con y sin schemas)
|
|
153
|
-
- β INSERTMANY
|
|
154
|
-
- β FIND (con filtros, sort, limit)
|
|
155
|
-
- β FINDONE
|
|
156
|
-
- β COUNT
|
|
157
|
-
- β UPDATE / UPDATEMANY
|
|
158
|
-
- β UPSERT
|
|
159
|
-
- β DELETE / DELETEMANY
|
|
160
|
-
- β AGGREGATE (pipelines)
|
|
161
|
-
- β DISTINCT
|
|
162
|
-
- β Schema validaciones dinΓ‘micas
|
|
163
|
-
- β Populate (referencias)
|
|
164
|
-
|
|
165
|
-
### MariaDB
|
|
166
|
-
- β INSERT
|
|
167
|
-
- β SELECT
|
|
168
|
-
- β UPDATE
|
|
169
|
-
- β DELETE
|
|
170
|
-
- β COUNT
|
|
171
|
-
- β WHERE queries
|
|
172
|
-
|
|
173
|
-
### PostgreSQL
|
|
174
|
-
- β INSERT (con RETURNING)
|
|
175
|
-
- β SELECT
|
|
176
|
-
- β UPDATE
|
|
177
|
-
- β DELETE
|
|
178
|
-
- β COUNT
|
|
179
|
-
- β WHERE queries
|
|
180
|
-
|
|
181
|
-
## π ValidaciΓ³n de Cierre de Conexiones
|
|
182
|
-
|
|
183
|
-
Las pruebas validan que:
|
|
184
|
-
1. Las conexiones se cierren correctamente despuΓ©s de cada operaciΓ³n
|
|
185
|
-
2. No haya fugas de memoria en operaciones mΓΊltiples
|
|
186
|
-
3. Los errores se manejen adecuadamente
|
|
187
|
-
4. El tiempo de respuesta sea razonable
|
|
188
|
-
|
|
189
|
-
## π Salida Esperada
|
|
190
|
-
|
|
191
|
-
```
|
|
192
|
-
=== INICIANDO PRUEBAS REDIS ===
|
|
193
|
-
|
|
194
|
-
1. Probando SET...
|
|
195
|
-
β SET exitoso: { set: 'test:bonsaif:key', expire: 60, ... }
|
|
196
|
-
|
|
197
|
-
2. Probando GET...
|
|
198
|
-
β GET exitoso: { get: 'test:bonsaif:key', res: 'test-value-...' }
|
|
199
|
-
|
|
200
|
-
...
|
|
201
|
-
|
|
202
|
-
=== β TODAS LAS PRUEBAS REDIS EXITOSAS ===
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## π Troubleshooting
|
|
206
|
-
|
|
207
|
-
### Error de conexiΓ³n
|
|
208
|
-
- Verifica que el servidor estΓ© corriendo
|
|
209
|
-
- Revisa las credenciales en `config.js`
|
|
210
|
-
- Comprueba los puertos
|
|
211
|
-
|
|
212
|
-
### Timeout
|
|
213
|
-
- Aumenta el timeout en la configuraciΓ³n del servidor
|
|
214
|
-
- Verifica la carga del servidor
|
|
215
|
-
|
|
216
|
-
### Tabla no existe (MariaDB/PostgreSQL)
|
|
217
|
-
- Ejecuta los scripts SQL de creaciΓ³n de tablas
|
|
218
|
-
- O usa `./docker-start.sh` que las crea automΓ‘ticamente
|
|
219
|
-
|
|
220
|
-
### Docker no inicia
|
|
221
|
-
```bash
|
|
222
|
-
# Verificar que Docker estΓ© corriendo
|
|
223
|
-
docker ps
|
|
224
|
-
|
|
225
|
-
# Ver logs de contenedor
|
|
226
|
-
docker logs bonsaif-redis
|
|
227
|
-
docker logs bonsaif-mongodb
|
|
228
|
-
docker logs bonsaif-mariadb
|
|
229
|
-
docker logs bonsaif-postgres
|
|
230
|
-
|
|
231
|
-
# Limpiar y reiniciar
|
|
232
|
-
./docker-stop.sh
|
|
233
|
-
./docker-start.sh
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Puerto ya en uso
|
|
237
|
-
```bash
|
|
238
|
-
# Verificar quΓ© estΓ‘ usando el puerto
|
|
239
|
-
lsof -i :6379 # Redis
|
|
240
|
-
lsof -i :27017 # MongoDB
|
|
241
|
-
lsof -i :3306 # MariaDB
|
|
242
|
-
lsof -i :5432 # PostgreSQL
|
|
243
|
-
|
|
244
|
-
# Detener proceso o cambiar puerto en config.js
|
|
245
|
-
```
|
package/tests/config.example.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConfiguraciΓ³n de ejemplo para pruebas locales
|
|
3
|
-
* Copia este archivo a config.js y ajusta los valores segΓΊn tu entorno
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
redis: {
|
|
8
|
-
endpoint: {
|
|
9
|
-
uri: 'redis://localhost:6379',
|
|
10
|
-
port: 6379,
|
|
11
|
-
debug: true
|
|
12
|
-
},
|
|
13
|
-
options: {}
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
mariadb: {
|
|
17
|
-
endpoint: {
|
|
18
|
-
uri: 'localhost',
|
|
19
|
-
port: 3306,
|
|
20
|
-
user: 'root',
|
|
21
|
-
password: '',
|
|
22
|
-
debug: true
|
|
23
|
-
},
|
|
24
|
-
options: {
|
|
25
|
-
db: 'test'
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
mongodb: {
|
|
30
|
-
endpoint: {
|
|
31
|
-
uri: 'mongodb://localhost:27017',
|
|
32
|
-
port: 27017,
|
|
33
|
-
poolSize: 10,
|
|
34
|
-
debug: true
|
|
35
|
-
},
|
|
36
|
-
options: {}
|
|
37
|
-
},
|
|
38
|
-
mongoose: {
|
|
39
|
-
endpoint: {
|
|
40
|
-
uri: 'mongodb://localhost:27017',
|
|
41
|
-
port: 27017,
|
|
42
|
-
poolSize: 10,
|
|
43
|
-
debug: false,
|
|
44
|
-
local: true,
|
|
45
|
-
client: 'mongoose'
|
|
46
|
-
},
|
|
47
|
-
options: {}
|
|
48
|
-
},
|
|
49
|
-
postgres: {
|
|
50
|
-
endpoint: {
|
|
51
|
-
uri: 'localhost',
|
|
52
|
-
port: 5432,
|
|
53
|
-
user: 'postgres',
|
|
54
|
-
password: '',
|
|
55
|
-
debug: true
|
|
56
|
-
},
|
|
57
|
-
options: {
|
|
58
|
-
db: 'test'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
package/tests/docker-restart.sh
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Script para reiniciar todos los contenedores Docker de pruebas
|
|
4
|
-
# Ejecutar: chmod +x docker-restart.sh && ./docker-restart.sh
|
|
5
|
-
|
|
6
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
7
|
-
echo "β REINICIANDO CONTENEDORES DOCKER BONSAIF β"
|
|
8
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
9
|
-
echo ""
|
|
10
|
-
|
|
11
|
-
# Detener contenedores
|
|
12
|
-
./docker-stop.sh
|
|
13
|
-
|
|
14
|
-
echo ""
|
|
15
|
-
echo "Esperando 3 segundos..."
|
|
16
|
-
sleep 3
|
|
17
|
-
echo ""
|
|
18
|
-
|
|
19
|
-
# Iniciar contenedores
|
|
20
|
-
./docker-start.sh
|
package/tests/docker-start.sh
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Script para levantar todos los contenedores Docker necesarios para pruebas
|
|
4
|
-
# Ejecutar: chmod +x docker-start.sh && ./docker-start.sh
|
|
5
|
-
|
|
6
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
7
|
-
echo "β INICIANDO CONTENEDORES DOCKER BONSAIF β"
|
|
8
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
9
|
-
echo ""
|
|
10
|
-
|
|
11
|
-
# Colores
|
|
12
|
-
GREEN='\033[0;32m'
|
|
13
|
-
YELLOW='\033[1;33m'
|
|
14
|
-
RED='\033[0;31m'
|
|
15
|
-
NC='\033[0m' # No Color
|
|
16
|
-
|
|
17
|
-
# FunciΓ³n para verificar si Docker estΓ‘ corriendo
|
|
18
|
-
check_docker() {
|
|
19
|
-
if ! docker info > /dev/null 2>&1; then
|
|
20
|
-
echo -e "${RED}β Error: Docker no estΓ‘ corriendo${NC}"
|
|
21
|
-
echo " Por favor inicia Docker Desktop primero"
|
|
22
|
-
exit 1
|
|
23
|
-
fi
|
|
24
|
-
echo -e "${GREEN}β Docker estΓ‘ corriendo${NC}"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
# FunciΓ³n para esperar a que un contenedor estΓ© listo
|
|
28
|
-
wait_for_container() {
|
|
29
|
-
local container=$1
|
|
30
|
-
local max_attempts=30
|
|
31
|
-
local attempt=1
|
|
32
|
-
|
|
33
|
-
echo -n " Esperando a que $container estΓ© listo..."
|
|
34
|
-
|
|
35
|
-
while [ $attempt -le $max_attempts ]; do
|
|
36
|
-
if docker ps --filter "name=$container" --filter "status=running" | grep -q $container; then
|
|
37
|
-
echo -e " ${GREEN}β${NC}"
|
|
38
|
-
return 0
|
|
39
|
-
fi
|
|
40
|
-
echo -n "."
|
|
41
|
-
sleep 1
|
|
42
|
-
attempt=$((attempt + 1))
|
|
43
|
-
done
|
|
44
|
-
|
|
45
|
-
echo -e " ${RED}β Timeout${NC}"
|
|
46
|
-
return 1
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# Verificar Docker
|
|
50
|
-
check_docker
|
|
51
|
-
echo ""
|
|
52
|
-
|
|
53
|
-
# 1. Redis
|
|
54
|
-
echo "βΆ Iniciando Redis..."
|
|
55
|
-
docker run -d \
|
|
56
|
-
--name bonsaif-redis \
|
|
57
|
-
-p 6379:6379 \
|
|
58
|
-
--restart unless-stopped \
|
|
59
|
-
redis:latest > /dev/null 2>&1
|
|
60
|
-
|
|
61
|
-
if [ $? -eq 0 ]; then
|
|
62
|
-
wait_for_container bonsaif-redis
|
|
63
|
-
else
|
|
64
|
-
if docker ps -a --filter "name=bonsaif-redis" | grep -q bonsaif-redis; then
|
|
65
|
-
echo -e " ${YELLOW}β Contenedor ya existe, iniciando...${NC}"
|
|
66
|
-
docker start bonsaif-redis > /dev/null 2>&1
|
|
67
|
-
wait_for_container bonsaif-redis
|
|
68
|
-
else
|
|
69
|
-
echo -e " ${RED}β Error al crear contenedor${NC}"
|
|
70
|
-
fi
|
|
71
|
-
fi
|
|
72
|
-
|
|
73
|
-
# 2. MongoDB
|
|
74
|
-
echo "βΆ Iniciando MongoDB..."
|
|
75
|
-
docker run -d \
|
|
76
|
-
--name bonsaif-mongodb \
|
|
77
|
-
-p 27017:27017 \
|
|
78
|
-
--restart unless-stopped \
|
|
79
|
-
mongo:latest > /dev/null 2>&1
|
|
80
|
-
|
|
81
|
-
if [ $? -eq 0 ]; then
|
|
82
|
-
wait_for_container bonsaif-mongodb
|
|
83
|
-
else
|
|
84
|
-
if docker ps -a --filter "name=bonsaif-mongodb" | grep -q bonsaif-mongodb; then
|
|
85
|
-
echo -e " ${YELLOW}β Contenedor ya existe, iniciando...${NC}"
|
|
86
|
-
docker start bonsaif-mongodb > /dev/null 2>&1
|
|
87
|
-
wait_for_container bonsaif-mongodb
|
|
88
|
-
else
|
|
89
|
-
echo -e " ${RED}β Error al crear contenedor${NC}"
|
|
90
|
-
fi
|
|
91
|
-
fi
|
|
92
|
-
|
|
93
|
-
# 3. MariaDB
|
|
94
|
-
echo "βΆ Iniciando MariaDB..."
|
|
95
|
-
docker run -d \
|
|
96
|
-
--name bonsaif-mariadb \
|
|
97
|
-
-p 3306:3306 \
|
|
98
|
-
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
|
|
99
|
-
-e MYSQL_DATABASE=test \
|
|
100
|
-
--restart unless-stopped \
|
|
101
|
-
mariadb:latest > /dev/null 2>&1
|
|
102
|
-
|
|
103
|
-
if [ $? -eq 0 ]; then
|
|
104
|
-
wait_for_container bonsaif-mariadb
|
|
105
|
-
echo " Esperando inicializaciΓ³n de MariaDB..."
|
|
106
|
-
sleep 5
|
|
107
|
-
|
|
108
|
-
# Crear tabla de prueba
|
|
109
|
-
echo " Creando tabla test_users..."
|
|
110
|
-
docker exec -i bonsaif-mariadb mariadb -u root test << EOF > /dev/null 2>&1
|
|
111
|
-
CREATE TABLE IF NOT EXISTS test_users (
|
|
112
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
113
|
-
name VARCHAR(100),
|
|
114
|
-
email VARCHAR(100),
|
|
115
|
-
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
116
|
-
);
|
|
117
|
-
EOF
|
|
118
|
-
if [ $? -eq 0 ]; then
|
|
119
|
-
echo -e " ${GREEN}β Tabla creada${NC}"
|
|
120
|
-
else
|
|
121
|
-
echo -e " ${YELLOW}β No se pudo crear la tabla (puede que ya exista)${NC}"
|
|
122
|
-
fi
|
|
123
|
-
else
|
|
124
|
-
if docker ps -a --filter "name=bonsaif-mariadb" | grep -q bonsaif-mariadb; then
|
|
125
|
-
echo -e " ${YELLOW}β Contenedor ya existe, iniciando...${NC}"
|
|
126
|
-
docker start bonsaif-mariadb > /dev/null 2>&1
|
|
127
|
-
wait_for_container bonsaif-mariadb
|
|
128
|
-
else
|
|
129
|
-
echo -e " ${RED}β Error al crear contenedor${NC}"
|
|
130
|
-
fi
|
|
131
|
-
fi
|
|
132
|
-
|
|
133
|
-
# 4. PostgreSQL
|
|
134
|
-
echo "βΆ Iniciando PostgreSQL..."
|
|
135
|
-
docker run -d \
|
|
136
|
-
--name bonsaif-postgres \
|
|
137
|
-
-p 5432:5432 \
|
|
138
|
-
-e POSTGRES_PASSWORD=postgres \
|
|
139
|
-
-e POSTGRES_DB=test \
|
|
140
|
-
--restart unless-stopped \
|
|
141
|
-
postgres:latest > /dev/null 2>&1
|
|
142
|
-
|
|
143
|
-
if [ $? -eq 0 ]; then
|
|
144
|
-
wait_for_container bonsaif-postgres
|
|
145
|
-
echo " Esperando inicializaciΓ³n de PostgreSQL..."
|
|
146
|
-
sleep 5
|
|
147
|
-
|
|
148
|
-
# Crear tabla de prueba
|
|
149
|
-
echo " Creando tabla test_users..."
|
|
150
|
-
docker exec -i bonsaif-postgres psql -U postgres -d test << EOF > /dev/null 2>&1
|
|
151
|
-
CREATE TABLE IF NOT EXISTS test_users (
|
|
152
|
-
id SERIAL PRIMARY KEY,
|
|
153
|
-
name VARCHAR(100),
|
|
154
|
-
email VARCHAR(100),
|
|
155
|
-
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
156
|
-
);
|
|
157
|
-
EOF
|
|
158
|
-
if [ $? -eq 0 ]; then
|
|
159
|
-
echo -e " ${GREEN}β Tabla creada${NC}"
|
|
160
|
-
else
|
|
161
|
-
echo -e " ${YELLOW}β No se pudo crear la tabla (puede que ya exista)${NC}"
|
|
162
|
-
fi
|
|
163
|
-
else
|
|
164
|
-
if docker ps -a --filter "name=bonsaif-postgres" | grep -q bonsaif-postgres; then
|
|
165
|
-
echo -e " ${YELLOW}β Contenedor ya existe, iniciando...${NC}"
|
|
166
|
-
docker start bonsaif-postgres > /dev/null 2>&1
|
|
167
|
-
wait_for_container bonsaif-postgres
|
|
168
|
-
else
|
|
169
|
-
echo -e " ${RED}β Error al crear contenedor${NC}"
|
|
170
|
-
fi
|
|
171
|
-
fi
|
|
172
|
-
|
|
173
|
-
# Mostrar estado final
|
|
174
|
-
echo ""
|
|
175
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
176
|
-
echo "β ESTADO DE CONTENEDORES β"
|
|
177
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
178
|
-
echo ""
|
|
179
|
-
|
|
180
|
-
docker ps --filter "name=bonsaif-" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
|
181
|
-
|
|
182
|
-
echo ""
|
|
183
|
-
echo -e "${GREEN}β Todos los contenedores estΓ‘n listos${NC}"
|
|
184
|
-
echo ""
|
|
185
|
-
echo "Credenciales de conexiΓ³n:"
|
|
186
|
-
echo " Redis: localhost:6379"
|
|
187
|
-
echo " MongoDB: mongodb://localhost:27017"
|
|
188
|
-
echo " MariaDB: localhost:3306 (user: root, password: vacΓo)"
|
|
189
|
-
echo " PostgreSQL: localhost:5432 (user: postgres, password: postgres)"
|
|
190
|
-
echo ""
|
|
191
|
-
echo "Para detener: ./docker-stop.sh"
|
|
192
|
-
echo "Para ver logs: docker logs <nombre-contenedor>"
|
package/tests/docker-stop.sh
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Script para detener y eliminar todos los contenedores Docker de pruebas
|
|
4
|
-
# Ejecutar: chmod +x docker-stop.sh && ./docker-stop.sh
|
|
5
|
-
|
|
6
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
7
|
-
echo "β DETENIENDO CONTENEDORES DOCKER BONSAIF β"
|
|
8
|
-
echo "ββββββββββββββββββββββββββββββββββββββββββββββ"
|
|
9
|
-
echo ""
|
|
10
|
-
|
|
11
|
-
# Colores
|
|
12
|
-
GREEN='\033[0;32m'
|
|
13
|
-
YELLOW='\033[1;33m'
|
|
14
|
-
RED='\033[0;31m'
|
|
15
|
-
NC='\033[0m'
|
|
16
|
-
|
|
17
|
-
CONTAINERS=(
|
|
18
|
-
"bonsaif-redis"
|
|
19
|
-
"bonsaif-mongodb"
|
|
20
|
-
"bonsaif-mariadb"
|
|
21
|
-
"bonsaif-postgres"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
echo "Deteniendo y eliminando contenedores..."
|
|
25
|
-
echo ""
|
|
26
|
-
|
|
27
|
-
for container in "${CONTAINERS[@]}"; do
|
|
28
|
-
if docker ps -a --filter "name=$container" | grep -q $container; then
|
|
29
|
-
echo -n "βΆ $container..."
|
|
30
|
-
docker stop $container > /dev/null 2>&1
|
|
31
|
-
docker rm $container > /dev/null 2>&1
|
|
32
|
-
echo -e " ${GREEN}β eliminado${NC}"
|
|
33
|
-
else
|
|
34
|
-
echo -e "βΆ $container... ${YELLOW}no existe${NC}"
|
|
35
|
-
fi
|
|
36
|
-
done
|
|
37
|
-
|
|
38
|
-
echo ""
|
|
39
|
-
echo -e "${GREEN}β Limpieza completada${NC}"
|
|
40
|
-
echo ""
|
|
41
|
-
echo "Para volver a iniciar: ./docker-start.sh"
|
package/tests/run-all-tests.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Script para ejecutar todas las pruebas de conexiones
|
|
3
|
-
* Ejecutar: node tests/run-all-tests.js (desde raΓz)
|
|
4
|
-
* O tambiΓ©n: node run-all-tests.js (desde tests/)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { exec } = require('child_process');
|
|
8
|
-
const util = require('util');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const execPromise = util.promisify(exec);
|
|
11
|
-
|
|
12
|
-
// Directorio donde estΓ‘ este script
|
|
13
|
-
const testsDir = __dirname;
|
|
14
|
-
|
|
15
|
-
const tests = [
|
|
16
|
-
{ name: 'Redis', file: 'test-redis.js' },
|
|
17
|
-
{ name: 'MongoDB', file: 'test-mongodb.js' },
|
|
18
|
-
{ name: 'Mongoose', file: 'test-mongoose.js' },
|
|
19
|
-
{ name: 'MariaDB', file: 'test-mariadb.js' },
|
|
20
|
-
{ name: 'PostgreSQL', file: 'test-postgres.js' }
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
async function runAllTests() {
|
|
24
|
-
console.log('ββββββββββββββββββββββββββββββββββββββββββββββ');
|
|
25
|
-
console.log('β EJECUTANDO TODAS LAS PRUEBAS BONSAIF β');
|
|
26
|
-
console.log('ββββββββββββββββββββββββββββββββββββββββββββββ\n');
|
|
27
|
-
|
|
28
|
-
const results = [];
|
|
29
|
-
|
|
30
|
-
for (const test of tests) {
|
|
31
|
-
console.log(`\n${'='.repeat(50)}`);
|
|
32
|
-
console.log(`βΆ ${test.name.toUpperCase()}`);
|
|
33
|
-
console.log('='.repeat(50) + '\n');
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
// Construir ruta completa al archivo de test
|
|
37
|
-
const testPath = path.join(testsDir, test.file);
|
|
38
|
-
const { stdout, stderr } = await execPromise(`node "${testPath}"`);
|
|
39
|
-
console.log(stdout);
|
|
40
|
-
if (stderr && stderr.trim()) {
|
|
41
|
-
console.error('STDERR:', stderr);
|
|
42
|
-
}
|
|
43
|
-
results.push({ name: test.name, status: 'β EXITOSO', error: null });
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error(error.stdout || error.message);
|
|
46
|
-
if (error.stderr) {
|
|
47
|
-
console.error('STDERR:', error.stderr);
|
|
48
|
-
}
|
|
49
|
-
results.push({ name: test.name, status: 'β FALLIDO', error: error.message });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Resumen
|
|
54
|
-
console.log('\nββββββββββββββββββββββββββββββββββββββββββββββ');
|
|
55
|
-
console.log('β RESUMEN DE PRUEBAS β');
|
|
56
|
-
console.log('ββββββββββββββββββββββββββββββββββββββββββββββ\n');
|
|
57
|
-
|
|
58
|
-
results.forEach(result => {
|
|
59
|
-
const status = result.status.includes('β') ? 'β' : 'β';
|
|
60
|
-
console.log(`${status} ${result.name.padEnd(20)} ${result.status}`);
|
|
61
|
-
if (result.error) {
|
|
62
|
-
console.log(` Error: ${result.error.split('\n')[0]}`);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const failed = results.filter(r => r.status.includes('β'));
|
|
67
|
-
const passed = results.filter(r => r.status.includes('β'));
|
|
68
|
-
|
|
69
|
-
console.log(`\nTotal: ${results.length} | Exitosas: ${passed.length} | Fallidas: ${failed.length}\n`);
|
|
70
|
-
|
|
71
|
-
if (failed.length > 0) {
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
runAllTests();
|