1- import { DifferV3 } from '@api7/adc-differ' ;
1+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2+ import { Differ } from '@api7/adc-differ' ;
23import * as ADCSDK from '@api7/adc-sdk' ;
34
45import { BackendAPISIXStandalone } from '../../src' ;
6+ import { rawConfig as rawConfigCache } from '../../src/cache' ;
57import { server1 , token1 } from '../support/constants' ;
68import {
79 createEvent ,
@@ -11,6 +13,7 @@ import {
1113 syncEvents ,
1214} from '../support/utils' ;
1315
16+ const cacheKey = 'default' ;
1417describe ( 'Service E2E' , ( ) => {
1518 let backend : BackendAPISIXStandalone ;
1619
@@ -19,7 +22,7 @@ describe('Service E2E', () => {
1922 backend = new BackendAPISIXStandalone ( {
2023 server : server1 ,
2124 token : token1 ,
22- cacheKey : 'default' ,
25+ cacheKey,
2326 } ) ;
2427 } ) ;
2528
@@ -51,10 +54,7 @@ describe('Service E2E', () => {
5154 expect ( dumpConfiguration ( backend ) ) . resolves . not . toThrow ( ) ) ;
5255
5356 it ( 'Create services' , async ( ) =>
54- syncEvents (
55- backend ,
56- DifferV3 . diff ( { services : [ service1 , service2 ] } , { } ) ,
57- ) ) ;
57+ syncEvents ( backend , Differ . diff ( { services : [ service1 , service2 ] } , { } ) ) ) ;
5858
5959 it ( 'Dump' , async ( ) => {
6060 const result = ( await dumpConfiguration ( backend ) ) as ADCSDK . Configuration ;
@@ -68,7 +68,7 @@ describe('Service E2E', () => {
6868 newService . description = 'desc' ;
6969 await syncEvents (
7070 backend ,
71- DifferV3 . diff (
71+ Differ . diff (
7272 { services : [ newService , service2 ] } ,
7373 await dumpConfiguration ( backend ) ,
7474 ) ,
@@ -171,4 +171,36 @@ describe('Service E2E', () => {
171171 expect ( result . services ) . toHaveLength ( 0 ) ;
172172 } ) ;
173173 } ) ;
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+ } ) ;
174206} ) ;
0 commit comments