1
- import { DifferV3 } from '@api7/adc-differ' ;
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { Differ } from '@api7/adc-differ' ;
2
3
import * as ADCSDK from '@api7/adc-sdk' ;
3
4
4
5
import { BackendAPISIXStandalone } from '../../src' ;
6
+ import { rawConfig as rawConfigCache } from '../../src/cache' ;
5
7
import { server1 , token1 } from '../support/constants' ;
6
8
import {
7
9
createEvent ,
@@ -11,6 +13,7 @@ import {
11
13
syncEvents ,
12
14
} from '../support/utils' ;
13
15
16
+ const cacheKey = 'default' ;
14
17
describe ( 'Service E2E' , ( ) => {
15
18
let backend : BackendAPISIXStandalone ;
16
19
@@ -19,7 +22,7 @@ describe('Service E2E', () => {
19
22
backend = new BackendAPISIXStandalone ( {
20
23
server : server1 ,
21
24
token : token1 ,
22
- cacheKey : 'default' ,
25
+ cacheKey,
23
26
} ) ;
24
27
} ) ;
25
28
@@ -51,10 +54,7 @@ describe('Service E2E', () => {
51
54
expect ( dumpConfiguration ( backend ) ) . resolves . not . toThrow ( ) ) ;
52
55
53
56
it ( 'Create services' , async ( ) =>
54
- syncEvents (
55
- backend ,
56
- DifferV3 . diff ( { services : [ service1 , service2 ] } , { } ) ,
57
- ) ) ;
57
+ syncEvents ( backend , Differ . diff ( { services : [ service1 , service2 ] } , { } ) ) ) ;
58
58
59
59
it ( 'Dump' , async ( ) => {
60
60
const result = ( await dumpConfiguration ( backend ) ) as ADCSDK . Configuration ;
@@ -68,7 +68,7 @@ describe('Service E2E', () => {
68
68
newService . description = 'desc' ;
69
69
await syncEvents (
70
70
backend ,
71
- DifferV3 . diff (
71
+ Differ . diff (
72
72
{ services : [ newService , service2 ] } ,
73
73
await dumpConfiguration ( backend ) ,
74
74
) ,
@@ -171,4 +171,36 @@ describe('Service E2E', () => {
171
171
expect ( result . services ) . toHaveLength ( 0 ) ;
172
172
} ) ;
173
173
} ) ;
174
+
175
+ describe ( 'Sync service with upstream service discovery' , ( ) => {
176
+ const registryName = 'consul' ;
177
+ const serviceName = 'svc-upstream-sd' ;
178
+ const service : ADCSDK . Service = {
179
+ name : serviceName ,
180
+ upstream : {
181
+ type : 'roundrobin' ,
182
+ discovery_type : registryName ,
183
+ service_name : serviceName ,
184
+ } ,
185
+ } ;
186
+
187
+ it ( 'Create service' , async ( ) =>
188
+ syncEvents (
189
+ backend ,
190
+ Differ . diff ( { services : [ service ] } , await dumpConfiguration ( backend ) ) ,
191
+ ) ) ;
192
+
193
+ it ( 'Check raw cache' , async ( ) => {
194
+ const rawCache = rawConfigCache . get ( cacheKey ) ;
195
+ expect ( rawCache ! . upstreams ) . toHaveLength ( 1 ) ;
196
+
197
+ const upstream = rawCache ! . upstreams ! [ 0 ] ;
198
+ expect ( upstream . nodes ) . toBeUndefined ( ) ;
199
+ expect ( upstream . discovery_type ) . toBe ( registryName ) ;
200
+ expect ( upstream . service_name ) . toBe ( serviceName ) ;
201
+ } ) ;
202
+
203
+ it ( 'Delete service' , async ( ) =>
204
+ syncEvents ( backend , Differ . diff ( { } , await dumpConfiguration ( backend ) ) ) ) ;
205
+ } ) ;
174
206
} ) ;
0 commit comments