@@ -2,6 +2,7 @@ package extension
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67
78 "github.com/mcpchecker/mcpchecker/pkg/extension/sdk"
@@ -65,13 +66,99 @@ func TestHandleWait(t *testing.T) {
6566 wantSuccess : false ,
6667 },
6768 {
68- name : "missing condition field" ,
69+ name : "missing condition field checks existence " ,
6970 args : map [string ]any {
7071 "apiVersion" : "v1" ,
7172 "kind" : "Pod" ,
7273 "metadata" : map [string ]any {"name" : "test" },
74+ "timeout" : "1s" ,
75+ },
76+ client : & mockClient {
77+ getFn : func (ctx context.Context , gvr schema.GroupVersionResource , name , namespace string ) (* unstructured.Unstructured , error ) {
78+ return & unstructured.Unstructured {
79+ Object : map [string ]any {
80+ "apiVersion" : "v1" ,
81+ "kind" : "Pod" ,
82+ "metadata" : map [string ]any {"name" : "test" },
83+ },
84+ }, nil
85+ },
86+ },
87+ wantSuccess : true ,
88+ },
89+ {
90+ name : "no condition - resource not found times out" ,
91+ args : map [string ]any {
92+ "apiVersion" : "v1" ,
93+ "kind" : "Pod" ,
94+ "metadata" : map [string ]any {"name" : "test" },
95+ "timeout" : "1s" ,
96+ },
97+ client : & mockClient {
98+ getFn : func (ctx context.Context , gvr schema.GroupVersionResource , name , namespace string ) (* unstructured.Unstructured , error ) {
99+ return nil , fmt .Errorf ("not found" )
100+ },
101+ },
102+ wantSuccess : false ,
103+ },
104+ {
105+ name : "no condition - succeeds when resource exists" ,
106+ args : map [string ]any {
107+ "apiVersion" : "networking.istio.io/v1" ,
108+ "kind" : "Gateway" ,
109+ "metadata" : map [string ]any {"name" : "my-gateway" , "namespace" : "istio-system" },
110+ "timeout" : "2s" ,
111+ },
112+ client : & mockClient {
113+ getFn : func (ctx context.Context , gvr schema.GroupVersionResource , name , namespace string ) (* unstructured.Unstructured , error ) {
114+ return & unstructured.Unstructured {
115+ Object : map [string ]any {
116+ "apiVersion" : "networking.istio.io/v1" ,
117+ "kind" : "Gateway" ,
118+ "metadata" : map [string ]any {
119+ "name" : "my-gateway" ,
120+ "namespace" : "istio-system" ,
121+ },
122+ "spec" : map [string ]any {
123+ "selector" : map [string ]any {
124+ "istio" : "ingressgateway" ,
125+ },
126+ },
127+ },
128+ }, nil
129+ },
130+ },
131+ wantSuccess : true ,
132+ },
133+ {
134+ name : "resource without status.conditions times out (e.g. Istio Gateway)" ,
135+ args : map [string ]any {
136+ "apiVersion" : "networking.istio.io/v1" ,
137+ "kind" : "Gateway" ,
138+ "metadata" : map [string ]any {"name" : "my-gateway" , "namespace" : "istio-system" },
139+ "condition" : "Available" ,
140+ "status" : "True" ,
141+ "timeout" : "2s" ,
142+ },
143+ client : & mockClient {
144+ getFn : func (ctx context.Context , gvr schema.GroupVersionResource , name , namespace string ) (* unstructured.Unstructured , error ) {
145+ return & unstructured.Unstructured {
146+ Object : map [string ]any {
147+ "apiVersion" : "networking.istio.io/v1" ,
148+ "kind" : "Gateway" ,
149+ "metadata" : map [string ]any {
150+ "name" : "my-gateway" ,
151+ "namespace" : "istio-system" ,
152+ },
153+ "spec" : map [string ]any {
154+ "selector" : map [string ]any {
155+ "istio" : "ingressgateway" ,
156+ },
157+ },
158+ },
159+ }, nil
160+ },
73161 },
74- client : & mockClient {},
75162 wantSuccess : false ,
76163 },
77164 }
0 commit comments