Skip to content

Commit

Permalink
test: http proxy (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Mar 27, 2023
1 parent e431444 commit 7b11f5e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jobs:
- name: Build
run: pnpm build

- name: Install tinyproxy
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install tinyproxy
tinyproxy
- name: Test
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
Expand Down
94 changes: 93 additions & 1 deletion tests/specs/cli/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default testSuite(({ describe }) => {
return;
}

describe('CLI', async ({ test }) => {
describe('CLI', async ({ test, describe }) => {
const files = {
'.aicommits': `OPENAI_KEY=${OPENAI_KEY}`,
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
Expand Down Expand Up @@ -133,5 +133,97 @@ export default testSuite(({ describe }) => {

await fixture.rm();
});

describe('proxy', ({ test }) => {
test('Fails on invalid proxy', async () => {
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\nproxy=http://localhost:1234`,
});
const git = await createGit(fixture.path);

await git('add', ['data.json']);

const committing = aicommits([], {
reject: false,
});

committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
if (stdout.match('└')) {
committing.stdin!.write('y');
committing.stdin!.end();
}
});

const { stdout, exitCode } = await committing;

expect(exitCode).toBe(1);
expect(stdout).toMatch('connect ECONNREFUSED');

await fixture.rm();
});

test('Connects with config', async () => {
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\nproxy=http://localhost:8888`,
});
const git = await createGit(fixture.path);

await git('add', ['data.json']);

const committing = aicommits();

committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
if (stdout.match('└')) {
committing.stdin!.write('y');
committing.stdin!.end();
}
});

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);

await fixture.rm();
});

test('Connects with env variable', async () => {
const { fixture, aicommits } = await createFixture(files);
const git = await createGit(fixture.path);

await git('add', ['data.json']);

const committing = aicommits([], {
env: {
HTTP_PROXY: 'http://localhost:8888',
},
});

committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
if (stdout.match('└')) {
committing.stdin!.write('y');
committing.stdin!.end();
}
});

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
console.log('Committed with:', commitMessage);

await fixture.rm();
});
});
});
});

0 comments on commit 7b11f5e

Please sign in to comment.