@@ -580,8 +580,6 @@ func (s *Scaffold) GetMetricsEndpoint() string {
580580 s .addFinalizers (tunnel .Close )
581581 return fmt .Sprintf ("http://%s/metrics" , tunnel .Endpoint ())
582582}
583- << << << < HEAD
584- == == == =
585583
586584func (s * Scaffold ) NewWebsocketClient (tls * tls.Config , path string , headers http.Header ) * websocket.Conn {
587585 var host = s .ApisixHTTPEndpoint ()
@@ -616,105 +614,3 @@ func (s *Scaffold) NewWebsocketClient(tls *tls.Config, path string, headers http
616614 }).ShouldNot (HaveOccurred (), "establishing websocket connection" )
617615 return conn
618616}
619-
620- func (s * Scaffold ) ControlAPIClient () (ControlAPIClient , error ) {
621- tunnel := k8s .NewTunnel (s .kubectlOptions , k8s .ResourceTypeService , "apisix-control-api" , 9090 , 9090 )
622- if err := tunnel .ForwardPortE (s .t ); err != nil {
623- return nil , err
624- }
625- s .addFinalizers (tunnel .Close )
626-
627- return & controlAPI {
628- client : NewClient ("http" , tunnel .Endpoint ()),
629- }, nil
630- }
631-
632- func (s * Scaffold ) EnsureNumService (controlAPIClient ControlAPIClient , matcher func (result int ) bool ) error {
633- times := 0
634- return wait .PollUntilContextTimeout (context .Background (), 100 * time .Millisecond , 10 * time .Minute , true , func (ctx context.Context ) (done bool , err error ) {
635- times ++
636- results , _ , err := controlAPIClient .ListServices ()
637- if err != nil {
638- log .Errorw ("failed to ListServices" , zap .Error (err ))
639- return false , nil
640- }
641- if ! matcher (len (results )) {
642- log .Debugw ("number of effective services" , zap .Int ("number" , len (results )), zap .Int ("times" , times ))
643- return false , nil
644- }
645- return true , nil
646- })
647- }
648-
649- func (s * Scaffold ) ExpectUpstream (controlAPIClient ControlAPIClient , name string , matcher func (upstream adctypes.Upstream ) bool ) error {
650- times := 0
651- return wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 10 * time .Minute , true , func (ctx context.Context ) (done bool , err error ) {
652- times ++
653- upstreams , _ , err := controlAPIClient .ListUpstreams ()
654- if err != nil {
655- log .Errorw ("failed to ListServices" , zap .Error (err ))
656- return false , nil
657- }
658- for _ , upstream := range upstreams {
659- upsValue := upstream .(map [string ]any )
660- data , err := json .Marshal (upsValue ["value" ])
661- if err != nil {
662- return false , fmt .Errorf ("failed to marshal upstream: %v" , err )
663- }
664-
665- var ups adctypes.Upstream
666- if err := json .Unmarshal (data , & ups ); err != nil {
667- return false , fmt .Errorf ("failed to unmarshal upstream: %v" , err )
668- }
669- if name != "" && ups .Name != name {
670- continue
671- }
672- if ok := matcher (ups ); ! ok {
673- return false , nil
674- }
675- }
676- return true , nil
677- })
678- }
679-
680- func (s * Scaffold ) EnsureNumUpstreamNodes (controlAPIClient ControlAPIClient , name string , number int ) error {
681- return s .ExpectUpstream (controlAPIClient , name , func (upstream adctypes.Upstream ) bool {
682- if len (upstream .Nodes ) != number {
683- log .Warnf ("expect upstream: [%s] nodes num to be %d, but got %d" , upstream .Name , number , len (upstream .Nodes ))
684- return false
685- }
686- return true
687- })
688- }
689-
690- type ControlAPIClient interface {
691- ListServices () ([]any , int64 , error )
692- ListUpstreams () ([]any , int64 , error )
693- }
694-
695- type controlAPI struct {
696- client * httpexpect.Expect
697- }
698-
699- func (c * controlAPI ) ListUpstreams () (result []any , total int64 , err error ) {
700- resp := c .client .Request (http .MethodGet , "/v1/upstreams" ).Expect ()
701- if resp .Raw ().StatusCode != http .StatusOK {
702- return nil , 0 , fmt .Errorf ("unexpected status code: %v, message: %s" , resp .Raw ().StatusCode , resp .Body ().Raw ())
703- }
704- if err = json .Unmarshal ([]byte (resp .Body ().Raw ()), & result ); err != nil {
705- return nil , 0 , fmt .Errorf ("failed to unmarshal response body: %w" , err )
706- }
707- return result , int64 (len (result )), err
708- }
709-
710- func (c * controlAPI ) ListServices () (result []any , total int64 , err error ) {
711- resp := c .client .Request (http .MethodGet , "/v1/services" ).Expect ()
712- if resp .Raw ().StatusCode != http .StatusOK {
713- return nil , 0 , fmt .Errorf ("unexpected status code: %v, message: %s" , resp .Raw ().StatusCode , resp .Body ().Raw ())
714- }
715- if err = json .Unmarshal ([]byte (resp .Body ().Raw ()), & result ); err != nil {
716- return nil , 0 , fmt .Errorf ("failed to unmarshal response body: %w" , err )
717- }
718- return result , int64 (len (result )), err
719- }
720- >> >> >> > b70e22eb (fix : wss related tests are unstable (#2675 ))
0 commit comments