Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,41 @@ describe('Service E2E - inline upstream', () => {
expect(rawConfig?.stream_routes_conf_version).toBeUndefined();
});

it('Delete service', async () => {
it('Update inlined upstream again', async () => {
vi.useFakeTimers();
vi.setSystemTime(300);

const newConfig = structuredClone(config);
newConfig.services[0].upstream.nodes = [];

const events = DifferV3.diff(newConfig, await dumpConfiguration(backend));
expect(events).toHaveLength(1);
expect(events[0].type).toEqual(ADCSDK.EventType.UPDATE);
expect(events[0].resourceType).toEqual(ADCSDK.ResourceType.SERVICE);
expect(events[0].diff?.[0].path?.[0]).toEqual('upstream');

return syncEvents(backend, events);
});

it('Check configuration', () => {
const rawConfig = rawConfigCache.get(cacheKey);
expect(rawConfig?.upstreams?.[0].modifiedIndex).toEqual(300);
expect(rawConfig?.upstreams?.[0].nodes).toHaveLength(0);
expect(rawConfig?.services?.[0].modifiedIndex).toEqual(100);
expect(rawConfig?.upstreams_conf_version).toEqual(300);
expect(rawConfig?.services_conf_version).toEqual(100);
expect(rawConfig?.consumers_conf_version).toBeUndefined();
expect(rawConfig?.global_rules_conf_version).toBeUndefined();
expect(rawConfig?.plugin_metadata_conf_version).toBeUndefined();
expect(rawConfig?.routes_conf_version).toBeUndefined();
expect(rawConfig?.ssls_conf_version).toBeUndefined();
expect(rawConfig?.stream_routes_conf_version).toBeUndefined();
});

it('Delete service', async () => {
vi.useFakeTimers();
vi.setSystemTime(400);

const events = DifferV3.diff({}, await dumpConfiguration(backend));
expect(events).toHaveLength(1);
expect(events[0].type).toEqual(ADCSDK.EventType.DELETE);
Expand All @@ -124,7 +155,7 @@ describe('Service E2E - inline upstream', () => {
const rawConfig = rawConfigCache.get(cacheKey);
expect(rawConfig?.upstreams).toHaveLength(0);
expect(rawConfig?.services).toHaveLength(0);
expect(rawConfig?.upstreams_conf_version).toEqual(300);
expect(rawConfig?.services_conf_version).toEqual(300);
expect(rawConfig?.upstreams_conf_version).toEqual(400);
expect(rawConfig?.services_conf_version).toEqual(400);
});
});
3 changes: 1 addition & 2 deletions libs/backend-apisix-standalone/src/operator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { DifferV3 } from '@api7/adc-differ';
import * as ADCSDK from '@api7/adc-sdk';
import axios, {
type AxiosError,
type AxiosInstance,
type AxiosResponse,
} from 'axios';
import { cloneDeep, isNil, unset } from 'lodash';
import { cloneDeep, unset } from 'lodash';
import { createHash } from 'node:crypto';
import {
type ObservableInput,
Expand Down
Loading