@@ -25,6 +25,7 @@ import (
2525 "knative.dev/func/pkg/docker"
2626 fn "knative.dev/func/pkg/functions"
2727 "knative.dev/func/pkg/k8s"
28+ "knative.dev/func/pkg/keda"
2829 "knative.dev/func/pkg/knative"
2930 "knative.dev/func/pkg/oci"
3031 "knative.dev/func/pkg/pipelines/tekton"
@@ -44,26 +45,34 @@ const (
4445 TestNamespace = "default"
4546)
4647
47- func newRemoteTestClient (verbose bool , opts ... fn.Option ) * fn.Client {
48+ func newRemoteTestClient (verbose bool , deployer string , opts ... fn.Option ) * fn.Client {
4849 baseOpts := []fn.Option {
4950 fn .WithBuilder (buildpacks .NewBuilder (buildpacks .WithVerbose (verbose ))),
5051 fn .WithPusher (docker .NewPusher (docker .WithCredentialsProvider (testCP ))),
51- fn .WithDeployer (knative .NewDeployer (knative .WithDeployerVerbose (verbose ))),
52- fn .WithDescribers (knative .NewDescriber (verbose ), k8s .NewDescriber (verbose )),
53- fn .WithListers (knative .NewLister (verbose ), k8s .NewLister (verbose )),
54- fn .WithRemovers (knative .NewRemover (verbose ), k8s .NewRemover (verbose )),
52+ fn .WithDescribers (knative .NewDescriber (verbose ), k8s .NewDescriber (verbose ), keda .NewDescriber (verbose )),
53+ fn .WithListers (knative .NewLister (verbose ), k8s .NewLister (verbose ), keda .NewLister (verbose )),
54+ fn .WithRemovers (knative .NewRemover (verbose ), k8s .NewRemover (verbose ), keda .NewRemover (verbose )),
5555 fn .WithPipelinesProvider (tekton .NewPipelinesProvider (tekton .WithCredentialsProvider (testCP ), tekton .WithVerbose (verbose ))),
5656 }
57+
58+ switch deployer {
59+ case k8s .KubernetesDeployerName :
60+ baseOpts = append (baseOpts , fn .WithDeployer (k8s .NewDeployer (k8s .WithDeployerVerbose (verbose ))))
61+ case keda .KedaDeployerName :
62+ baseOpts = append (baseOpts , fn .WithDeployer (keda .NewDeployer (keda .WithDeployerVerbose (verbose ))))
63+ case knative .KnativeDeployerName :
64+ baseOpts = append (baseOpts , fn .WithDeployer (knative .NewDeployer (knative .WithDeployerVerbose (verbose ))))
65+ }
66+
5767 return fn .New (append (baseOpts , opts ... )... )
5868}
5969
6070// assertFunctionEchoes returns without error when the function of the given
6171// name echoes a parameter sent via a Get request.
62- func assertFunctionEchoes (url string ) (err error ) {
72+ func assertFunctionEchoes (httpClient * http. Client , url string ) (err error ) {
6373 token := time .Now ().Format ("20060102150405.000000000" )
6474
65- // res, err := http.Get("http://testremote-default.default.localtest.me?token=" + token)
66- res , err := http .Get (url + "?token=" + token )
75+ res , err := httpClient .Get (url + "?token=" + token )
6776 if err != nil {
6877 return
6978 }
@@ -82,6 +91,28 @@ func assertFunctionEchoes(url string) (err error) {
8291 return
8392}
8493
94+ // httpClientForDeployer returns an HTTP client appropriate for the deployer type.
95+ // Raw and keda deployers expose cluster-internal services, so an in-cluster
96+ // dialer is needed. Knative services are externally accessible via ingress.
97+ func httpClientForDeployer (t * testing.T , ctx context.Context , deployer string ) * http.Client {
98+ switch deployer {
99+ case k8s .KubernetesDeployerName , keda .KedaDeployerName :
100+ dialer , err := k8s .NewInClusterDialer (ctx , k8s .GetClientConfig ())
101+ if err != nil {
102+ t .Fatalf ("failed to create in-cluster dialer: %v" , err )
103+ }
104+ t .Cleanup (func () { _ = dialer .Close () })
105+ return & http.Client {
106+ Transport : & http.Transport {
107+ DialContext : dialer .DialContext ,
108+ },
109+ Timeout : time .Minute ,
110+ }
111+ default :
112+ return http .DefaultClient
113+ }
114+ }
115+
85116func tektonTestsEnabled (t * testing.T ) (enabled bool ) {
86117 enabled , _ = strconv .ParseBool (os .Getenv ("FUNC_INT_TEKTON_ENABLED" ))
87118 if ! enabled {
@@ -114,41 +145,51 @@ func TestInt_Remote_Default(t *testing.T) {
114145 t .Skip ()
115146 }
116147 skipOnUnsupportedArch (t )
117- _ = fromCleanEnvironment (t )
118- var (
119- err error
120- url string
121- verbose = false
122- ctx , cancel = signal .NotifyContext (t .Context (), os .Interrupt )
123- client = newRemoteTestClient (verbose ,
124- fn .WithRepository ("https://github.com/functions-dev/templates" ))
125- )
126- defer cancel ()
127-
128- f := fn.Function {
129- Name : "testremote-default" ,
130- Runtime : "go" ,
131- Template : "echo" ,
132- Registry : TestRegistry ,
133- Namespace : TestNamespace ,
134- Build : fn.BuildSpec {
135- Builder : "pack" , // TODO: test "s2i". Currently it causes a 'no space left on device' error in GH actions.
136- },
137- }
138148
139- if f , err = client .Init (f ); err != nil {
140- t .Fatal (err )
141- }
142-
143- if url , f , err = client .RunPipeline (ctx , f ); err != nil {
144- t .Fatal (err )
145- }
146- defer func () {
147- _ = client .Remove (ctx , "" , "" , f , true )
148- }()
149-
150- if err := assertFunctionEchoes (url ); err != nil {
151- t .Fatal (err )
149+ for _ , d := range []string {knative .KnativeDeployerName , k8s .KubernetesDeployerName , keda .KedaDeployerName } {
150+ t .Run (d , func (t * testing.T ) {
151+ _ = fromCleanEnvironment (t )
152+ var (
153+ err error
154+ url string
155+ verbose = false
156+ ctx , cancel = signal .NotifyContext (t .Context (), os .Interrupt )
157+ client = newRemoteTestClient (verbose , d ,
158+ fn .WithRepository ("https://github.com/functions-dev/templates" ))
159+ )
160+ defer cancel ()
161+
162+ f := fn.Function {
163+ Name : "testremote-default" ,
164+ Runtime : "go" ,
165+ Template : "echo" ,
166+ Registry : TestRegistry ,
167+ Namespace : TestNamespace ,
168+ Build : fn.BuildSpec {
169+ Builder : "pack" , // TODO: test "s2i". Currently it causes a 'no space left on device' error in GH actions.
170+ },
171+ Deploy : fn.DeploySpec {
172+ Deployer : d ,
173+ },
174+ }
175+
176+ if f , err = client .Init (f ); err != nil {
177+ t .Fatal (err )
178+ }
179+
180+ if url , f , err = client .RunPipeline (ctx , f ); err != nil {
181+ t .Fatal (err )
182+ }
183+ defer func () {
184+ _ = client .Remove (ctx , "" , "" , f , true )
185+ }()
186+
187+ httpClient := httpClientForDeployer (t , ctx , d )
188+
189+ if err := assertFunctionEchoes (httpClient , url ); err != nil {
190+ t .Fatal (err )
191+ }
192+ })
152193 }
153194}
154195
0 commit comments