|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + * or more contributor license agreements. See the NOTICE file |
| 5 | + * distributed with this work for additional information |
| 6 | + * regarding copyright ownership. The ASF licenses this file |
| 7 | + * to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance |
| 9 | + * with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, |
| 14 | + * software distributed under the License is distributed on an |
| 15 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + * KIND, either express or implied. See the License for the |
| 17 | + * specific language governing permissions and limitations |
| 18 | + * under the License. |
| 19 | + */ |
| 20 | + |
1 | 21 | import { beforeAll } from 'vitest';
|
2 | 22 |
|
3 | 23 | // Environment configuration - can be overridden for different environments
|
@@ -26,18 +46,46 @@ export const testConfig = {
|
26 | 46 | export function configureGitCredentials(tempDir: string): void {
|
27 | 47 | const { execSync } = require('child_process');
|
28 | 48 |
|
29 |
| - // Configure git credentials using URL rewriting |
30 |
| - const baseUrlParsed = new URL(testConfig.gitProxyBaseUrl); |
31 |
| - const credentialUrl = `${baseUrlParsed.protocol}//${testConfig.gitUsername}:${testConfig.gitPassword}@${baseUrlParsed.host}${baseUrlParsed.pathname}`; |
32 |
| - const insteadOfUrl = testConfig.gitProxyBaseUrl; |
| 49 | + try { |
| 50 | + // Configure git credentials using URL rewriting |
| 51 | + const baseUrlParsed = new URL(testConfig.gitProxyBaseUrl); |
33 | 52 |
|
34 |
| - execSync('git init', { cwd: tempDir, encoding: 'utf8' }); |
35 |
| - execSync(`git config url."${credentialUrl}".insteadOf ${insteadOfUrl}`, { |
36 |
| - cwd: tempDir, |
37 |
| - encoding: 'utf8', |
38 |
| - }); |
| 53 | + // Initialize git if not already done |
| 54 | + try { |
| 55 | + execSync('git rev-parse --git-dir', { cwd: tempDir, encoding: 'utf8', stdio: 'pipe' }); |
| 56 | + } catch { |
| 57 | + execSync('git init', { cwd: tempDir, encoding: 'utf8' }); |
| 58 | + } |
39 | 59 |
|
40 |
| - console.log(`Configured git credentials for ${insteadOfUrl}`); |
| 60 | + // Configure multiple URL patterns to catch all variations |
| 61 | + const patterns = [ |
| 62 | + // Most important: the proxy server itself (this is what's asking for auth) |
| 63 | + { |
| 64 | + insteadOf: `${baseUrlParsed.protocol}//${baseUrlParsed.host}`, |
| 65 | + credUrl: `${baseUrlParsed.protocol}//${testConfig.gitUsername}:${testConfig.gitPassword}@${baseUrlParsed.host}`, |
| 66 | + }, |
| 67 | + // Base URL with trailing slash |
| 68 | + { |
| 69 | + insteadOf: testConfig.gitProxyBaseUrl, |
| 70 | + credUrl: `${baseUrlParsed.protocol}//${testConfig.gitUsername}:${testConfig.gitPassword}@${baseUrlParsed.host}${baseUrlParsed.pathname}`, |
| 71 | + }, |
| 72 | + // Base URL without trailing slash |
| 73 | + { |
| 74 | + insteadOf: testConfig.gitProxyBaseUrl.replace(/\/$/, ''), |
| 75 | + credUrl: `${baseUrlParsed.protocol}//${testConfig.gitUsername}:${testConfig.gitPassword}@${baseUrlParsed.host}`, |
| 76 | + }, |
| 77 | + ]; |
| 78 | + |
| 79 | + for (const pattern of patterns) { |
| 80 | + execSync(`git config url."${pattern.credUrl}".insteadOf "${pattern.insteadOf}"`, { |
| 81 | + cwd: tempDir, |
| 82 | + encoding: 'utf8', |
| 83 | + }); |
| 84 | + } |
| 85 | + } catch (error) { |
| 86 | + console.error('Failed to configure git credentials:', error); |
| 87 | + throw error; |
| 88 | + } |
41 | 89 | }
|
42 | 90 |
|
43 | 91 | export async function waitForService(
|
@@ -78,9 +126,9 @@ beforeAll(async () => {
|
78 | 126 | console.log(`Git Username: ${testConfig.gitUsername}`);
|
79 | 127 | console.log(`Git Proxy Base URL: ${testConfig.gitProxyBaseUrl}`);
|
80 | 128 |
|
81 |
| - // Wait for the git proxy service to be ready |
| 129 | + // Wait for the git proxy UI service to be ready |
82 | 130 | // Note: Docker Compose should be started externally (e.g., in CI or manually)
|
83 |
| - await waitForService(`${testConfig.gitProxyUrl}/health`); |
| 131 | + await waitForService(`${testConfig.gitProxyUiUrl}/api/v1/healthcheck`); |
84 | 132 |
|
85 | 133 | console.log('E2E test environment is ready');
|
86 | 134 | }, testConfig.timeout);
|
0 commit comments