-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·107 lines (84 loc) · 2.88 KB
/
test.sh
File metadata and controls
executable file
·107 lines (84 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
log() {
echo -e "${GREEN}[TEST]${NC} $1"
}
fail() {
echo -e "${RED}[FAIL]${NC} $1"
exit 1
}
log "Testowanie jednostkowe (Jest)"
npx jest --config=jest.config.js --runInBand || fail "Testy jednostkowe nie powiodły się!"
log "Testowanie E2E (Playwright, Cypress lub Selenium jeśli dostępne)"
if [ -f "playwright.config.js" ]; then
npx playwright test || fail "Testy E2E (Playwright) nie powiodły się!"
elif [ -f "cypress.json" ]; then
npx cypress run || fail "Testy E2E (Cypress) nie powiodły się!"
elif [ -d "e2e" ]; then
for f in e2e/*.js; do
node "$f" || fail "Test E2E $f nie powiódł się!"
done
else
log "Brak skonfigurowanych testów E2E. Pomijam."
fi
log "Walidacja plików YAML (js-yaml)"
# Tworzymy tymczasowy skrypt walidacji YAML
cat > /tmp/yaml-validator.js << 'EOF'
const fs = require('fs');
const path = require('path');
const jsYaml = require('js-yaml');
function validateYamlFiles(dir) {
if (!fs.existsSync(dir)) {
console.log(`Katalog ${dir} nie istnieje. Pomijam.`);
return true;
}
let allValid = true;
const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files) {
const fullPath = path.join(dir, file.name);
if (file.isDirectory()) {
// Rekurencyjnie sprawdź podkatalogi
const subDirValid = validateYamlFiles(fullPath);
if (!subDirValid) allValid = false;
} else if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
try {
const content = fs.readFileSync(fullPath, 'utf8');
// Obsługa wielu dokumentów w jednym pliku (rozdzielonych ---)
const documents = content.split(/^---$/m);
// Jeśli mamy tylko jeden dokument (bez separatorów ---)
if (documents.length === 1) {
jsYaml.load(content);
} else {
// Walidacja wszystkich dokumentów w pliku
jsYaml.loadAll(content, function() {});
}
console.log(`✓ ${fullPath} - OK`);
} catch (error) {
console.error(`✗ ${fullPath} - BŁĄD: ${error.message}`);
allValid = false;
}
}
}
return allValid;
}
const dirs = process.argv.slice(2);
let success = true;
for (const dir of dirs) {
const dirValid = validateYamlFiles(dir);
if (!dirValid) success = false;
}
process.exit(success ? 0 : 1);
EOF
# Instalujemy js-yaml globalnie dla tego skryptu
npm install --no-save js-yaml
# Upewniamy się, że katalogi istnieją (tworzymy je jeśli nie)
mkdir -p kubernetes terraform ansible
# Uruchamiamy walidator
NODE_PATH=$(npm root) node /tmp/yaml-validator.js kubernetes/ terraform/ ansible/ || fail "Błąd w plikach YAML!"
log "Walidacja plików JSON (jsonlint)"
npx jsonlint models/**/*.json --quiet || log "Brak plików JSON do walidacji lub ostrzeżenia."
log "Testy i walidacje zakończone sukcesem!"
exit 0