Skip to content

Commit 44a40f8

Browse files
authored
E2E: Add SMTP tester (grafana#88392)
* E2E: Add SMTP tester * fix loadlocation issue when running tests on alpine * temporary update * add log * update run-suite * Update run-suite * Update run-suite * Update run-suite * Update yarn.lock * apply suggestions + cleanup logs * update yarn.lock & package.json * fix swagger
1 parent cc1d3d0 commit 44a40f8

File tree

7 files changed

+349
-4
lines changed

7 files changed

+349
-4
lines changed

cypress.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path');
44

55
const benchmarkPlugin = require('./e2e/cypress/plugins/benchmark/index');
66
const readProvisions = require('./e2e/cypress/plugins/readProvisions');
7+
const smtpTester = require('./e2e/cypress/plugins/smtpTester');
78
const typescriptPreprocessor = require('./e2e/cypress/plugins/typescriptPreprocessor');
89

910
module.exports = defineConfig({
@@ -27,6 +28,10 @@ module.exports = defineConfig({
2728
benchmarkPlugin.initialize(on, config);
2829
}
2930

31+
if (config.env['SMTP_PLUGIN_ENABLED'] === true) {
32+
smtpTester.initialize(on, config);
33+
}
34+
3035
on('task', {
3136
readProvisions: (filePaths) => readProvisions({ CWD: process.cwd(), filePaths }),
3237
});

e2e/cypress/plugins/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ const path = require('path');
44
const benchmarkPlugin = require('./benchmark');
55
const extendConfig = require('./extendConfig');
66
const readProvisions = require('./readProvisions');
7+
const smtpTester = require('./smtpTester');
78
const typescriptPreprocessor = require('./typescriptPreprocessor');
89

910
module.exports = (on, config) => {
1011
if (config.env['BENCHMARK_PLUGIN_ENABLED'] === true) {
1112
benchmarkPlugin.initialize(on, config);
1213
}
1314

15+
if (config.env['SMTP_PLUGIN_ENABLED'] === true) {
16+
smtpTester.initialize(on, config);
17+
}
18+
1419
on('file:preprocessor', typescriptPreprocessor);
1520
on('task', {
1621
log({ message, optional }) {

e2e/cypress/plugins/smtpTester.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const ms = require('smtp-tester');
2+
3+
const PORT = 7777;
4+
5+
const initialize = (on, config) => {
6+
// starts the SMTP server at localhost:7777
7+
const mailServer = ms.init(PORT);
8+
console.log('mail server at port %d', PORT);
9+
10+
let lastEmail = {};
11+
12+
// process all emails
13+
mailServer.bind((addr, id, email) => {
14+
lastEmail[email.headers.to] = email;
15+
});
16+
17+
on('task', {
18+
resetEmails(recipient) {
19+
if (recipient) {
20+
console.log('reset all emails for recipient %s', recipient);
21+
delete lastEmail[recipient];
22+
} else {
23+
console.log('reset all emails');
24+
lastEmail = {};
25+
}
26+
},
27+
28+
getLastEmail(email) {
29+
return lastEmail[email] || null;
30+
},
31+
});
32+
};
33+
34+
exports.initialize = initialize;

e2e/run-suite

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ case "$1" in
6666
;;
6767
"enterprise")
6868
echo "Enterprise"
69+
env[SMTP_PLUGIN_ENABLED]=true
6970
CLEANUP="rm -rf ./e2e/extensions-suite"
7071
SETUP="cp -Lr ./e2e/extensions ./e2e/extensions-suite"
7172
enterpriseSuite=$(basename "${args[1]}")
@@ -105,6 +106,11 @@ case "$1" in
105106
;;
106107
esac
107108
;;
109+
"enterprise-smtp")
110+
env[SMTP_PLUGIN_ENABLED]=true
111+
cypressConfig[specPattern]=./e2e/extensions/enterprise/smtp-suite/$testFilesForSingleSuite
112+
cypressConfig[video]=${args[1]}
113+
;;
108114

109115
*)
110116
cypressConfig[specPattern]=./e2e/"${args[0]}"/$testFilesForSingleSuite

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
"css-minimizer-webpack-plugin": "6.0.0",
166166
"cypress": "13.10.0",
167167
"cypress-file-upload": "5.0.8",
168+
"cypress-recurse": "^1.35.3",
168169
"esbuild": "0.20.2",
169170
"esbuild-loader": "4.1.0",
170171
"esbuild-plugin-browserslist": "^0.12.0",
@@ -217,6 +218,7 @@
217218
"rudder-sdk-js": "2.48.8",
218219
"sass": "1.77.4",
219220
"sass-loader": "14.2.1",
221+
"smtp-tester": "^2.1.0",
220222
"style-loader": "4.0.0",
221223
"stylelint": "16.6.1",
222224
"stylelint-config-sass-guidelines": "11.1.0",

pkg/setting/setting.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"path"
1717
"path/filepath"
1818
"regexp"
19-
"runtime"
2019
"strconv"
2120
"strings"
2221
"time"
@@ -1024,9 +1023,9 @@ func (cfg *Cfg) validateStaticRootPath() error {
10241023
func (cfg *Cfg) Load(args CommandLineArgs) error {
10251024
cfg.setHomePath(args)
10261025

1027-
// Fix for missing IANA db on Windows
1026+
// Fix for missing IANA db on Windows or Alpine
10281027
_, zoneInfoSet := os.LookupEnv(zoneInfo)
1029-
if runtime.GOOS == "windows" && !zoneInfoSet {
1028+
if !zoneInfoSet {
10301029
if err := os.Setenv(zoneInfo, filepath.Join(cfg.HomePath, "tools", "zoneinfo.zip")); err != nil {
10311030
cfg.Logger.Error("Can't set ZONEINFO environment variable", "err", err)
10321031
}

0 commit comments

Comments
 (0)