mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
e2e: fix ui tests (#19138)
This commit is contained in:
@@ -22,8 +22,9 @@ module.exports = async config => {
|
||||
const page = await context.newPage();
|
||||
await page.goto(NOMAD_ADDR+'/ui/settings/tokens');
|
||||
await page.fill('input[id="token-input"]', NOMAD_TOKEN);
|
||||
await page.click('button:has-text("Set Token")', {strict: true});
|
||||
await page.click('button:has-text("Sign in")', {strict: true});
|
||||
|
||||
await page.context().storageState({ path: 'storageState.json' });
|
||||
const { storageState } = config.projects[0].use;
|
||||
await page.context().storageState({ path: storageState });
|
||||
await browser.close();
|
||||
};
|
||||
|
||||
@@ -19,6 +19,17 @@ job "nomad-proxy" {
|
||||
}
|
||||
}
|
||||
|
||||
service {
|
||||
name = "nomad-proxy"
|
||||
port = "www"
|
||||
provider = "nomad"
|
||||
check {
|
||||
type = "tcp"
|
||||
interval = "1s"
|
||||
timeout = "2s"
|
||||
}
|
||||
}
|
||||
|
||||
task "nginx" {
|
||||
|
||||
driver = "docker"
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
// @ts-check
|
||||
const { devices } = require('@playwright/test');
|
||||
|
||||
export const STORAGE_STATE = 'storageState.json';
|
||||
|
||||
/** @type {import('@playwright/test').PlaywrightTestConfig} */
|
||||
const config = {
|
||||
forbidOnly: !!process.env.CI,
|
||||
@@ -19,7 +21,10 @@ const config = {
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
storageState: STORAGE_STATE,
|
||||
},
|
||||
},
|
||||
// disabling firefox temporarily because the container doesn't
|
||||
// include it and so it tries to automatically install it and
|
||||
@@ -31,7 +36,10 @@ const config = {
|
||||
// },
|
||||
{
|
||||
name: 'webkit',
|
||||
use: { ...devices['Desktop Safari'] },
|
||||
use: {
|
||||
...devices['Desktop Safari'],
|
||||
storageState: STORAGE_STATE,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
set -e
|
||||
set -eu
|
||||
|
||||
help() {
|
||||
cat <<EOF
|
||||
@@ -23,6 +23,8 @@ Usage: run.sh [subcommand] [options] [--help]
|
||||
This reverse proxy uses a self-signed cert. Will print a new NOMAD_ADDR
|
||||
address for you to use for test runs.
|
||||
|
||||
ci For use in CI: runs the proxy, then tests, then stops the proxy.
|
||||
|
||||
Environment Variables:
|
||||
NOMAD_ADDR Address of Nomad cluster or reverse proxy.
|
||||
NOMAD_TOKEN Authentication token.
|
||||
@@ -43,7 +45,9 @@ run_shell() {
|
||||
}
|
||||
|
||||
run() {
|
||||
exec docker run -it --rm \
|
||||
local tty_args=''
|
||||
[ -t 1 ] && tty_args='-it'
|
||||
docker run $tty_args --rm \
|
||||
-v $(pwd):/src \
|
||||
-w /src \
|
||||
-e NOMAD_ADDR=$NOMAD_ADDR \
|
||||
@@ -55,13 +59,51 @@ run() {
|
||||
}
|
||||
|
||||
run_proxy() {
|
||||
nomad namespace apply proxy
|
||||
nomad job run "./input/proxy.nomad"
|
||||
IP=$(nomad node status -json -verbose \
|
||||
$(nomad operator api '/v1/allocations?namespace=proxy' | jq -r '.[] | select(.JobID == "nomad-proxy") | .NodeID') \
|
||||
| jq -r '.Attributes."unique.platform.aws.public-ipv4"')
|
||||
echo "NOMAD_ADDR=https://$IP:6464"
|
||||
exit 0
|
||||
# sending these outputs to stderr so that 'export NOMAD_ADDR=' is the
|
||||
# only stdout line, for users to eval, or this script to write then source.
|
||||
nomad namespace apply proxy 1>&2
|
||||
nomad job run ./input/proxy.nomad 1>&2
|
||||
set +e
|
||||
IP="$(_get_aws_ip)"
|
||||
[ -n "$IP" ] || {
|
||||
>&2 echo 'falling back to service IP'
|
||||
IP="$(_get_svc_ip)"
|
||||
}
|
||||
set -e
|
||||
[ -n "$IP" ] || {
|
||||
>&2 echo 'unable to get an IP for nomad proxy...'
|
||||
exit 1 # bad form to exit from a function, but this is essential (and eval'd)
|
||||
}
|
||||
echo "export NOMAD_ADDR=https://$IP:6464"
|
||||
}
|
||||
|
||||
_get_aws_ip(){
|
||||
aws_metadata_url="http://169.254.169.254/latest/meta-data"
|
||||
nomad exec -namespace=proxy -job nomad-proxy \
|
||||
curl -s "$aws_metadata_url/public-ipv4"
|
||||
}
|
||||
|
||||
_get_svc_ip() {
|
||||
nomad service info -namespace=proxy \
|
||||
-t '{{ range . }}{{ .Address }}{{ end }}' \
|
||||
nomad-proxy
|
||||
}
|
||||
|
||||
stop_proxy() {
|
||||
# make sure addr isn't still pointed at the proxy
|
||||
export NOMAD_ADDR="${NOMAD_ADDR/6464/4646}"
|
||||
nomad job stop -namespace=proxy nomad-proxy
|
||||
nomad namespace delete proxy
|
||||
}
|
||||
|
||||
run_ci() {
|
||||
set -x
|
||||
run_proxy > /tmp/proxy_addr.env
|
||||
source /tmp/proxy_addr.env
|
||||
run_tests
|
||||
rc=$?
|
||||
stop_proxy
|
||||
exit $rc
|
||||
}
|
||||
|
||||
opt="$1"
|
||||
@@ -69,8 +111,8 @@ case $opt in
|
||||
help|--help|-h) help ;;
|
||||
proxy|--proxy) run_proxy ;;
|
||||
test|--test) shift ; run_tests "$@" ;;
|
||||
shell) shift ; run_shell ;;
|
||||
stop|--stop) stop_proxy ;;
|
||||
ci|--ci) run_ci ;;
|
||||
shell) shift ; run_shell "$@" ;;
|
||||
*) run_tests "$@" ;;
|
||||
esac
|
||||
|
||||
run_tests
|
||||
|
||||
@@ -19,6 +19,6 @@ test('authenticated users can see their policies', async ({ page }) => {
|
||||
await expect(logo).toBeVisible();
|
||||
|
||||
|
||||
const policies = page.locator('text=Policies')
|
||||
const policies = page.getByText('Policies');
|
||||
await expect(policies).toBeVisible();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user