Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sourceTag to PineconeConfiguration and additionalHeaders to data plane calls #197

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/control/__tests__/indexOperationsBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { indexOperationsBuilder } from '../indexOperationsBuilder';
import { Configuration } from '../../pinecone-generated-ts-fetch';

jest.mock('../../pinecone-generated-ts-fetch', () => ({
...jest.requireActual('../../pinecone-generated-ts-fetch'),
Configuration: jest.fn(),
}));

describe('indexOperationsBuilder', () => {
test('API Configuration basePath is set to api.pinecone.io by default', () => {
const config = { apiKey: 'test-api-key' };
indexOperationsBuilder(config);
expect(Configuration).toHaveBeenCalledWith(
expect.objectContaining({ basePath: 'https://api.pinecone.io' })
);
});

test('controllerHostUrl overwrites the basePath in API Configuration', () => {
const controllerHostUrl = 'https://test-controller-host-url.io';
const config = {
apiKey: 'test-api-key',
controllerHostUrl,
};
indexOperationsBuilder(config);
expect(Configuration).toHaveBeenCalledWith(
expect.objectContaining({ basePath: controllerHostUrl })
);
});

test('additionalHeaders are passed to the API Configuration', () => {
const additionalHeaders = { 'x-test-header': 'test-value' };
const config = { apiKey: 'test-api-key', additionalHeaders };
indexOperationsBuilder(config);
expect(Configuration).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.objectContaining(additionalHeaders),
})
);
});
});
2 changes: 1 addition & 1 deletion src/control/indexOperationsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const indexOperationsBuilder = (
apiKey,
queryParamsStringify,
headers: {
'User-Agent': buildUserAgent(),
'User-Agent': buildUserAgent(config),
...headers,
},
fetchApi: getFetch(config),
Expand Down
29 changes: 26 additions & 3 deletions src/data/__tests__/dataOperationsProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { DataOperationsProvider } from '../dataOperationsProvider';
import { IndexHostSingleton } from '../indexHostSingleton';
import { Configuration } from '../../pinecone-generated-ts-fetch';

jest.mock('../../pinecone-generated-ts-fetch', () => ({
...jest.requireActual('../../pinecone-generated-ts-fetch'),
Configuration: jest.fn(),
}));

describe('DataOperationsProvider', () => {
let real;
const config = {
apiKey: 'test-api-key',
};

beforeAll(() => {
real = IndexHostSingleton.getHostUrl;
Expand Down Expand Up @@ -41,9 +50,6 @@ describe('DataOperationsProvider', () => {
});

test('passing indexHostUrl skips hostUrl resolution', async () => {
const config = {
apiKey: 'test-api-key',
};
const indexHostUrl = 'http://index-host-url';
const provider = new DataOperationsProvider(
config,
Expand All @@ -58,4 +64,21 @@ describe('DataOperationsProvider', () => {
expect(IndexHostSingleton.getHostUrl).not.toHaveBeenCalled();
expect(provider.buildDataOperationsConfig).toHaveBeenCalled();
});

test('passing additionalHeaders applies them to the API Configuration', async () => {
const additionalHeaders = { 'x-custom-header': 'custom-value' };
const provider = new DataOperationsProvider(
config,
'index-name',
undefined,
additionalHeaders
);

await provider.provide();
expect(Configuration).toHaveBeenCalledWith(
expect.objectContaining({
headers: expect.objectContaining(additionalHeaders),
})
);
});
});
Loading
Loading