Skip to content

Commit

Permalink
set cluster context, and check https in installed apps
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Jan 30, 2025
1 parent fefaac5 commit 3e7e509
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions scripts/pit/its/cc-identity-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const {log, err, args, createPage, closePage, takeScreenshot, waitForServerReady

log(`Checking that ${app} installed in ${url} is running ...\n`);
// When app is not running, localization cannot be enabled
let pageApp = await createPage(arg.headless, true);
let pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await takeScreenshot(pageApp, __filename, 'app-running');
await closePage(pageApp);
Expand Down Expand Up @@ -83,7 +83,7 @@ const {log, err, args, createPage, closePage, takeScreenshot, waitForServerReady
await takeScreenshot(page, __filename, 'user-created');

log(`Logging in ${app} as ${user} ...\n`);
pageApp = await createPage(arg.headless, true);
pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await takeScreenshot(pageApp, __filename, `app-${app}-loaded`);
await pageApp.getByLabel('Email').fill(user);
Expand Down
8 changes: 5 additions & 3 deletions scripts/pit/its/cc-localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const { assert } = require('console');

log(`Checking that ${app} installed in ${url} is running ...\n`);
// When app is not running, localization cannot be enabled
const pageApp = await createPage(arg.headless, true);
const pageApp = await createPage(arg.headless, arg.ignoreHTTPSErrors);
await waitForServerReady(pageApp, url);
await takeScreenshot(pageApp, __filename, 'app-running');
await closePage(pageApp);
Expand Down Expand Up @@ -82,7 +82,8 @@ const { assert } = require('console');

log(`Testing that preview page: ${previewUrl} is up and running\n`);
await page.getByRole('button', { name: 'Start preview' }).click();
const pagePrev = await createPage(arg.headless, true);
await page.waitForTimeout(5000);
const pagePrev = await createPage(arg.headless, true /* preview pages do not have a valid certificate */);
await waitForServerReady(pagePrev, previewUrl);
await takeScreenshot(pagePrev, __filename, 'preview-ready');
const text = await pagePrev.getByText(/Password|Dashboard/).textContent();
Expand All @@ -94,7 +95,8 @@ const { assert } = require('console');
await expect(pagePrev.getByRole('button', { name: 'New order' })).toBeVisible();
await takeScreenshot(pagePrev, __filename, 'preview-loaded');
}
// await expect(pagePrev.getByText('Panaderia', { exact: true })).toBeVisible();
// TODO: bakery is not internationalized
// await expect(pagePrev.getByText('Panaderia', { exact: true })).toBeVisible();
await closePage(pagePrev);

log('Cleaning up...\n');
Expand Down
10 changes: 7 additions & 3 deletions scripts/pit/its/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function log(...args) {
function out(...args) {
process.stderr.write(`\x1b[2m\x1b[196m${args}\x1b[0m`);
}
function echo(...args) {
process.stderr.write(`\x1b[2m\x1b[0;32m${args}\x1b[0m`);
}

function warn(...args) {
process.stderr.write(`\x1b[2m\x1b[91m${args}\x1b[0m`);
}
Expand Down Expand Up @@ -67,7 +71,7 @@ async function createPage(headless, ignoreHTTPSErrors) {
const page = await context.newPage();
page.on('console', msg => {
const text = `${msg.text()} - ${msg.location().url}`.replace(/\s+/g, ' ');
if (!/vaadinPush/.test(text)) out("> CONSOLE:", text, '\n');
if (!/vaadinPush|favicon.ico/.test(text)) out("> CONSOLE:", text, '\n');
});
page.on('pageerror', e => warn("> JSERROR:", ('' + e).replace(/\s+/g, ' '), '\n'));
page.browser = browser;
Expand All @@ -92,7 +96,7 @@ async function takeScreenshot(page, name, descr) {
// Wait for the server to be ready and to get a valid response
async function waitForServerReady(page, url, options = {}) {
const {
maxRetries = 20, // Max number of retries
maxRetries = 35, // Max number of retries
retryInterval = 5000 // Interval between retries in milliseconds
} = options;

Expand All @@ -103,7 +107,7 @@ async function waitForServerReady(page, url, options = {}) {
const response = await page.goto(url, {timeout: 120000});
// Check if the response status is not 503
if (response && response.status() < 400) {
out(` Attempt ${attempt} Server is ready and returned a valid response. ${response.status()}\n`);
echo(` Attempt ${attempt} Server is ready and returned a valid response. ${response.status()}\n`);
page.waitForTimeout(1500);
return response;
} else {
Expand Down
19 changes: 15 additions & 4 deletions scripts/pit/lib/lib-ccenter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ getTLs() {
}

checkTls() {
log "Checking TLS certificates for all ingresses hosted in the cluster"
[ -n "$TEST" -o -n "$SKIPHELM" ] && return 0
for i in `kubectl get ingresses -n $CC_NS | grep nginx | awk '{print $1}'`; do
getTLs "$i"
Expand Down Expand Up @@ -151,11 +152,23 @@ runPwTests() {
[ -z "$CC_CERT" -o -z "$CC_KEY" ] && NO_TLS=--notls || NO_TLS=""
for f in $CC_TESTS; do
runPlaywrightTests "$PIT_SCR_FOLDER/its/$f" "" "prod" "control-center" --url=https://$CC_CONTROL --login=$CC_EMAIL $NO_TLS || return 1
[ "$f" = cc-install-apps.js ] && reloadIngress
[ "$f" = cc-install-apps.js ] && reloadIngress && checkTls || return 1
sleep 3
done
}

setClusterContext() {
[ "$1" = "$CC_CLUSTER" ] && current=kind-$1 || current=$1
ns=$2
H=`kubectl config get-contexts | tr '*' ' ' | awk '{print $1}' | egrep "^$current$"`
[ -z "$H" ] && log "Cluster $current not found in kubectl contexts" && return 1
runCmd "$TEST" "Setting context to $current" "kubectl config use-context $current" || return 1
H=`kubectl config current-context`
[ "$H" != "$current" ] && log "Current context is not $current" && return 1
runCmd "$TEST" "Setting default namespace to $ns" "kubectl config set-context --current --namespace=$ns" || return 1
kubectl get ns >/dev/null 2>&1 || return 1
}

## Main method for running control center
runControlCenter() {
CLUSTER=${CLUSTER:-$CC_CLUSTER}
Expand All @@ -167,9 +180,7 @@ runControlCenter() {
[ "$CLUSTER" != "$CC_CLUSTER" ] || createKindCluster $CC_CLUSTER $CC_NS || return 1

## Set the context to the cluster
kubectl config set-context $CLUSTER || return 1
kubectl config set-context --current --namespace=$CC_NS || return 1
kubectl get ns >/dev/null 2>&1 || return 1
setClusterContext "$CLUSTER" "$CC_NS" || return 1

## Clean up CC from a previous run unless SKIPHELM is set
[ -z "$SKIPHELM" ] && uninstallCC $CLUSTER $CC_NS
Expand Down

0 comments on commit 3e7e509

Please sign in to comment.