|  | 
|  | 1 | +/** | 
|  | 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more | 
|  | 3 | + * contributor license agreements.  See the NOTICE file distributed with | 
|  | 4 | + * this work for additional information regarding copyright ownership. | 
|  | 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 | 
|  | 6 | + * (the "License"); you may not use this file except in compliance with | 
|  | 7 | + * the License.  You may obtain a copy of the License at | 
|  | 8 | + * | 
|  | 9 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | + * | 
|  | 11 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 12 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | + * See the License for the specific language governing permissions and | 
|  | 15 | + * limitations under the License. | 
|  | 16 | + */ | 
|  | 17 | +/** | 
|  | 18 | + * Licensed to the Apache Software Foundation (ASF) under one or more | 
|  | 19 | + * contributor license agreements.  See the NOTICE file distributed with | 
|  | 20 | + * this work for additional information regarding copyright ownership. | 
|  | 21 | + * The ASF licenses this file to You under the Apache License, Version 2.0 | 
|  | 22 | + * (the "License"); you may not use this file except in compliance with | 
|  | 23 | + * the License.  You may obtain a copy of the License at | 
|  | 24 | + * | 
|  | 25 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 26 | + * | 
|  | 27 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 28 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 29 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 30 | + * See the License for the specific language governing permissions and | 
|  | 31 | + * limitations under the License. | 
|  | 32 | + */ | 
|  | 33 | +import { exec } from 'node:child_process'; | 
|  | 34 | +import { readFile, writeFile } from 'node:fs/promises'; | 
|  | 35 | +import path from 'node:path'; | 
|  | 36 | +import { promisify } from 'node:util'; | 
|  | 37 | + | 
|  | 38 | +import { streamRoutesPom } from '@e2e/pom/stream_routes'; | 
|  | 39 | +import { test } from '@e2e/utils/test'; | 
|  | 40 | +import { expect } from '@playwright/test'; | 
|  | 41 | +import { produce, type WritableDraft } from 'immer'; | 
|  | 42 | +import { parse, stringify } from 'yaml'; | 
|  | 43 | + | 
|  | 44 | +const execAsync = promisify(exec); | 
|  | 45 | + | 
|  | 46 | +type APISIXConf = { | 
|  | 47 | +  apisix: { | 
|  | 48 | +    proxy_mode: string; | 
|  | 49 | +  }; | 
|  | 50 | +}; | 
|  | 51 | + | 
|  | 52 | +const getE2EServerDir = () => { | 
|  | 53 | +  const currentDir = new URL('.', import.meta.url).pathname; | 
|  | 54 | +  return path.join(currentDir, '../server'); | 
|  | 55 | +}; | 
|  | 56 | + | 
|  | 57 | +const updateAPISIXConf = async ( | 
|  | 58 | +  func: (v: WritableDraft<APISIXConf>) => void | 
|  | 59 | +) => { | 
|  | 60 | +  const confPath = path.join(getE2EServerDir(), 'apisix_conf.yml'); | 
|  | 61 | +  const fileContent = await readFile(confPath, 'utf-8'); | 
|  | 62 | +  const config = parse(fileContent) as APISIXConf; | 
|  | 63 | + | 
|  | 64 | +  const updatedContent = stringify(produce(config, func)); | 
|  | 65 | +  await writeFile(confPath, updatedContent, 'utf-8'); | 
|  | 66 | +}; | 
|  | 67 | + | 
|  | 68 | +const restartDockerServices = async () => { | 
|  | 69 | +  await execAsync('docker compose restart apisix', { cwd: getE2EServerDir() }); | 
|  | 70 | +  const url = 'http://127.0.0.1:6174/ui/'; | 
|  | 71 | +  const maxRetries = 20; | 
|  | 72 | +  const interval = 1000; | 
|  | 73 | +  for (let i = 0; i < maxRetries; i++) { | 
|  | 74 | +    const res = await fetch(url); | 
|  | 75 | +    if (res.ok) return; | 
|  | 76 | +    await new Promise((resolve) => setTimeout(resolve, interval)); | 
|  | 77 | +  } | 
|  | 78 | +  throw new Error('APISIX is not ready'); | 
|  | 79 | +}; | 
|  | 80 | + | 
|  | 81 | +test.beforeAll(async () => { | 
|  | 82 | +  await updateAPISIXConf((d) => { | 
|  | 83 | +    d.apisix.proxy_mode = 'http'; | 
|  | 84 | +  }); | 
|  | 85 | +  await restartDockerServices(); | 
|  | 86 | +}); | 
|  | 87 | + | 
|  | 88 | +test.afterAll(async () => { | 
|  | 89 | +  await updateAPISIXConf((d) => { | 
|  | 90 | +    d.apisix.proxy_mode = 'http&stream'; | 
|  | 91 | +  }); | 
|  | 92 | +  await restartDockerServices(); | 
|  | 93 | +}); | 
|  | 94 | + | 
|  | 95 | +test('show disabled error', async ({ page }) => { | 
|  | 96 | +  await streamRoutesPom.toIndex(page); | 
|  | 97 | + | 
|  | 98 | +  await expect(page.locator('main > span')).toContainText( | 
|  | 99 | +    'stream mode is disabled, can not add stream routes' | 
|  | 100 | +  ); | 
|  | 101 | + | 
|  | 102 | +  // Verify the error message is still shown after refresh | 
|  | 103 | +  await page.reload(); | 
|  | 104 | +  await expect(page.locator('main > span')).toContainText( | 
|  | 105 | +    'stream mode is disabled, can not add stream routes' | 
|  | 106 | +  ); | 
|  | 107 | +}); | 
0 commit comments