Skip to content

Commit c8fe9bb

Browse files
CLI-179 add network test for install.sh script
1 parent 3338958 commit c8fe9bb

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SonarQube CLI
3+
* Copyright (C) 2026 SonarSource Sàrl
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
21+
// Real-network test for install.sh — validates URL path structure on binaries.sonarsource.com
22+
23+
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
24+
import { mkdtempSync, rmSync, existsSync, readFileSync } from 'node:fs';
25+
import { join } from 'node:path';
26+
import { tmpdir } from 'node:os';
27+
28+
const scriptDir = join(import.meta.dir, '../../../../user-scripts');
29+
30+
describe('install.sh (network)', () => {
31+
let tempHome: string;
32+
33+
beforeEach(() => {
34+
tempHome = mkdtempSync(join(tmpdir(), 'sonar-install-test-'));
35+
});
36+
37+
afterEach(() => {
38+
rmSync(tempHome, { recursive: true, force: true });
39+
});
40+
41+
it(
42+
'downloads and installs sonar CLI binary on the current platform',
43+
() => {
44+
const scriptPath = join(scriptDir, 'install.sh');
45+
46+
const scriptContent = readFileSync(scriptPath, 'utf-8');
47+
const versionMatch = /^\s*version="([\d.]+)"/m.exec(scriptContent);
48+
if (!versionMatch) throw new Error('Could not parse version from install.sh');
49+
const expectedVersion = versionMatch[1];
50+
51+
const proc = Bun.spawnSync(['bash', scriptPath], {
52+
env: { HOME: tempHome, PATH: process.env.PATH! },
53+
});
54+
55+
expect(proc.exitCode).toBe(0);
56+
57+
const binaryPath = join(tempHome, '.local/share/sonarqube-cli/bin/sonar');
58+
expect(existsSync(binaryPath)).toBe(true);
59+
60+
const versionProc = Bun.spawnSync([binaryPath, '--version'], {
61+
env: { HOME: tempHome, PATH: process.env.PATH! },
62+
});
63+
const versionOutput = new TextDecoder().decode(versionProc.stdout);
64+
expect(versionOutput).toContain(expectedVersion);
65+
},
66+
{ timeout: 120000 },
67+
);
68+
});

0 commit comments

Comments
 (0)