Skip to content

Commit 0c7b849

Browse files
authored
refactor(tests): change remote url for testing (#46)
* add test token * change dummy repo url * fix * vendored ssh/https * maybe? * perl * skip linux gnu * skip linux gnu
1 parent 0636e82 commit 0c7b849

File tree

5 files changed

+72
-30
lines changed

5 files changed

+72
-30
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,20 @@ jobs:
7878
target: aarch64-apple-darwin
7979
build: yarn build --target aarch64-apple-darwin
8080
- host: windows-latest
81-
build: yarn build --target x86_64-pc-windows-msvc
8281
target: x86_64-pc-windows-msvc
82+
build: yarn build --target x86_64-pc-windows-msvc
8383
- host: ubuntu-latest
8484
target: x86_64-unknown-linux-gnu
85-
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig
86-
build: |-
87-
set -e &&
88-
apt update &&
89-
apt install -y pkg-config build-essential libssl-dev librust-openssl-dev openssl libz-dev zlib1g-dev lib32z1-dev &&
90-
RUSTFLAGS='-C link-args=-L/usr/lib/x86_64-linux-gnu/' yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.17 &&
91-
strip *.node
85+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
86+
build: yarn build --target x86_64-unknown-linux-gnu
9287
- host: ubuntu-latest
9388
target: x86_64-unknown-linux-musl
9489
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
95-
build: set -e && apk add --no-cache --update perl musl-dev pkgconfig openssl-dev && yarn build && strip *.node
90+
build: |-
91+
# perl nees for building openssl
92+
set -e &&
93+
apk add perl &&
94+
yarn build
9695
name: stable - ${{ matrix.settings.target }} - node@20
9796
runs-on: ${{ matrix.settings.host }}
9897
steps:
@@ -178,6 +177,8 @@ jobs:
178177
shell: bash
179178
- name: Test bindings
180179
run: yarn vitest run
180+
env:
181+
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
181182
test-windows-binding:
182183
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
183184
needs:
@@ -212,6 +213,8 @@ jobs:
212213
shell: bash
213214
- name: Test bindings
214215
run: yarn vitest run
216+
env:
217+
TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
215218
test-linux-x64-gnu-binding:
216219
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
217220
needs:
@@ -242,7 +245,7 @@ jobs:
242245
run: ls -R .
243246
shell: bash
244247
- name: Test bindings
245-
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn vitest run
248+
run: docker run --rm -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn vitest run
246249
test-linux-x64-musl-binding:
247250
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
248251
needs:
@@ -275,4 +278,4 @@ jobs:
275278
run: ls -R .
276279
shell: bash
277280
- name: Test bindings
278-
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn vitest run
281+
run: docker run --rm -e TEST_GITHUB_TOKEN=${{ secrets.TEST_GITHUB_TOKEN }} -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn vitest run

tests/diff.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
22
import path from 'node:path';
33
import { describe, expect, it } from 'vitest';
44
import { type DiffDelta, type DiffFile, openRepository } from '../index';
5-
import { WIN32 } from './env';
5+
import { TARGET } from './env';
66
import { useFixture } from './fixtures';
77
import type { FlattenMethods } from './types';
88

@@ -90,7 +90,7 @@ describe('diff', () => {
9090

9191
// Windows track all files when 'includeUntracked' option is enabled.
9292
// Need to look further into why.
93-
it('get diff include untracked', { skip: WIN32 }, async () => {
93+
it('get diff include untracked', { skip: TARGET[0] === 'win32' }, async () => {
9494
const p = await useFixture('commits');
9595
const repo = await openRepository(p);
9696
await fs.writeFile(path.join(p, 'third'), 'third created');

tests/env.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
export const CI = !!process.env.CI;
2-
export const LINUX = process.platform === 'linux';
3-
export const WIN32 = process.platform === 'win32';
2+
3+
function getTarget() {
4+
switch (process.platform) {
5+
case 'win32': {
6+
switch (process.arch) {
7+
case 'x64':
8+
return ['win32', 'x64'] as const;
9+
case 'ia32':
10+
return ['win32', 'ia32'] as const;
11+
case 'arm64':
12+
return ['win32', 'arm64'] as const;
13+
}
14+
break;
15+
}
16+
case 'darwin': {
17+
switch (process.arch) {
18+
case 'x64':
19+
return ['darwin', 'x64'] as const;
20+
case 'arm64':
21+
return ['darwin', 'arm64'] as const;
22+
}
23+
break;
24+
}
25+
case 'linux': {
26+
const isMusl = !(process.report.getReport() as any).header.glibcVersionRuntime;
27+
const type = isMusl ? 'musl' : 'gnu';
28+
switch (process.arch) {
29+
case 'x64':
30+
return ['linux', 'x64', type] as const;
31+
case 'arm64':
32+
return ['linux', 'arm64', type] as const;
33+
}
34+
}
35+
}
36+
throw new Error('Unsupported target');
37+
}
38+
39+
export const TARGET = getTarget();

tests/remote.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { describe, expect, it } from 'vitest';
22
import { cloneRepository, openRepository } from '../index';
3-
import { LINUX } from './env';
3+
import { TARGET } from './env';
44
import { useFixture } from './fixtures';
55
import { makeTmpDir } from './tmp';
66

77
describe('remote', () => {
8-
it('get remote names', { skip: LINUX }, async () => {
8+
const isLinuxGnu = TARGET[0] === 'linux' && TARGET[2] === 'gnu';
9+
10+
it('get remote names', { skip: isLinuxGnu }, async () => {
911
const p = await makeTmpDir('clone');
10-
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
12+
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
1113
expect(repo.remoteNames()).toContain('origin');
1214
});
1315

14-
it('get remote', { skip: LINUX }, async () => {
16+
it('get remote', { skip: isLinuxGnu }, async () => {
1517
const p = await makeTmpDir('clone');
16-
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
18+
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
1719
const remote = repo.getRemote('origin');
1820
expect(remote.name()).toEqual('origin');
19-
expect(remote.url()).toEqual('https://github.com/toss/es-toolkit');
21+
expect(remote.url()).toEqual('https://github.com/seokju-na/dummy-repo');
2022
expect(() => repo.getRemote('not_exists')).toThrowError(/libgit2 error: remote 'not_exists' does not exist/);
2123
});
2224

@@ -36,16 +38,16 @@ describe('remote', () => {
3638
expect(remote.name()).toEqual('origin');
3739
});
3840

39-
it('fetch remote', { skip: LINUX }, async () => {
41+
it('fetch remote', { skip: isLinuxGnu }, async () => {
4042
const p = await makeTmpDir('clone');
41-
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
43+
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
4244
const remote = repo.getRemote('origin');
4345
await remote.fetch(['main']);
4446
});
4547

46-
it('get remote default branch', { skip: LINUX }, async () => {
48+
it('get remote default branch', { skip: isLinuxGnu }, async () => {
4749
const p = await makeTmpDir('clone');
48-
const repo = await cloneRepository('https://github.com/toss/es-toolkit', p);
50+
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
4951
const remote = repo.getRemote('origin');
5052
const branch = await remote.defaultBranch();
5153
expect(branch).toEqual('refs/heads/main');

tests/repository.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
22
import path from 'node:path';
33
import { describe, expect, it } from 'vitest';
44
import { cloneRepository, initRepository, openRepository } from '../index';
5-
import { CI, LINUX } from './env';
5+
import { CI, TARGET } from './env';
66
import { useFixture } from './fixtures';
77
import { makeTmpDir } from './tmp';
88

@@ -35,19 +35,20 @@ describe('Repository', () => {
3535
await expect(fs.readFile(path.join(p, 'first'), 'utf8')).resolves.toEqual(expect.stringContaining('first'));
3636
});
3737

38-
it('clone from remote', { skip: LINUX }, async () => {
38+
it('clone from remote', { skip: TARGET[0] === 'linux' && TARGET[2] === 'gnu' }, async () => {
3939
const p = await makeTmpDir('clone');
4040
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo', p);
4141
expect(repo.state()).toBe('Clean');
4242
});
4343

44-
it('clone from remote with credential', { skip: CI || LINUX }, async () => {
44+
it('clone from remote with credential', { skip: !CI }, async () => {
4545
const p = await makeTmpDir('clone');
46-
const repo = await cloneRepository('git@github.com:seokju-na/dummy-repo', p, {
46+
const repo = await cloneRepository('https://github.com/seokju-na/dummy-repo-private', p, {
4747
fetch: {
4848
followRedirects: 'All',
4949
credential: {
50-
type: 'SSHKeyFromAgent',
50+
type: 'Plain',
51+
password: process.env.TEST_GITHUB_TOKEN!,
5152
},
5253
},
5354
});

0 commit comments

Comments
 (0)