@@ -24,6 +24,7 @@ import (
24
24
"net/http/httptest"
25
25
"os"
26
26
"testing"
27
+ "time"
27
28
28
29
"github.com/google/go-cmp/cmp"
29
30
"google.golang.org/api/option"
@@ -46,21 +47,25 @@ const (
46
47
configName = "default"
47
48
)
48
49
50
+ var defaultStatusCheckDeadline = 10 * time .Minute
51
+
49
52
func TestDeployService (tOuter * testing.T ) {
50
53
tests := []struct {
51
- description string
52
- toDeploy * run.Service
53
- defaultProject string
54
- region string
55
- expectedPath string
56
- httpErr int
57
- errCode proto.StatusCode
54
+ description string
55
+ toDeploy * run.Service
56
+ defaultProject string
57
+ region string
58
+ statusCheckDeadlineSec time.Duration
59
+ expectedPath string
60
+ httpErr int
61
+ errCode proto.StatusCode
58
62
}{
59
63
{
60
- description : "test deploy" ,
61
- defaultProject : "testProject" ,
62
- region : "us-central1" ,
63
- expectedPath : "/v1/projects/testProject/locations/us-central1/services" ,
64
+ description : "test deploy" ,
65
+ defaultProject : "testProject" ,
66
+ region : "us-central1" ,
67
+ expectedPath : "/v1/projects/testProject/locations/us-central1/services" ,
68
+ statusCheckDeadlineSec : defaultStatusCheckDeadline ,
64
69
toDeploy : & run.Service {
65
70
ApiVersion : "serving.knative.dev/v1" ,
66
71
Kind : "Service" ,
@@ -70,10 +75,25 @@ func TestDeployService(tOuter *testing.T) {
70
75
},
71
76
},
72
77
{
73
- description : "test deploy with specified project" ,
74
- defaultProject : "testProject" ,
75
- region : "us-central1" ,
76
- expectedPath : "/v1/projects/testProject/locations/us-central1/services" ,
78
+ description : "test deploy with status check deadline set to a non default value" ,
79
+ defaultProject : "testProject" ,
80
+ region : "us-central1" ,
81
+ expectedPath : "/v1/projects/testProject/locations/us-central1/services" ,
82
+ statusCheckDeadlineSec : 15 * time .Minute ,
83
+ toDeploy : & run.Service {
84
+ ApiVersion : "serving.knative.dev/v1" ,
85
+ Kind : "Service" ,
86
+ Metadata : & run.ObjectMeta {
87
+ Name : "test-service" ,
88
+ },
89
+ },
90
+ },
91
+ {
92
+ description : "test deploy with specified project" ,
93
+ defaultProject : "testProject" ,
94
+ region : "us-central1" ,
95
+ statusCheckDeadlineSec : defaultStatusCheckDeadline ,
96
+ expectedPath : "/v1/projects/testProject/locations/us-central1/services" ,
77
97
toDeploy : & run.Service {
78
98
ApiVersion : "serving.knative.dev/v1" ,
79
99
Kind : "Service" ,
@@ -84,10 +104,11 @@ func TestDeployService(tOuter *testing.T) {
84
104
},
85
105
},
86
106
{
87
- description : "test permission denied on deploy errors" ,
88
- defaultProject : "testProject" ,
89
- region : "us-central1" ,
90
- httpErr : http .StatusUnauthorized ,
107
+ description : "test permission denied on deploy errors" ,
108
+ defaultProject : "testProject" ,
109
+ region : "us-central1" ,
110
+ statusCheckDeadlineSec : defaultStatusCheckDeadline ,
111
+ httpErr : http .StatusUnauthorized ,
91
112
toDeploy : & run.Service {
92
113
ApiVersion : "serving.knative.dev/v1" ,
93
114
Kind : "Service" ,
@@ -99,8 +120,9 @@ func TestDeployService(tOuter *testing.T) {
99
120
errCode : proto .StatusCode_DEPLOY_CLOUD_RUN_GET_SERVICE_ERR ,
100
121
},
101
122
{
102
- description : "test no project specified" ,
103
- region : "us-central1" ,
123
+ description : "test no project specified" ,
124
+ region : "us-central1" ,
125
+ statusCheckDeadlineSec : defaultStatusCheckDeadline ,
104
126
toDeploy : & run.Service {
105
127
ApiVersion : "serving.knative.dev/v1" ,
106
128
Kind : "Service" ,
@@ -139,7 +161,14 @@ func TestDeployService(tOuter *testing.T) {
139
161
w .Write (b )
140
162
}))
141
163
142
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, configName )
164
+ deployer , _ := NewDeployer (
165
+ & runcontext.RunContext {},
166
+ & label.DefaultLabeller {},
167
+ & latest.CloudRunDeploy {
168
+ ProjectID : test .defaultProject ,
169
+ Region : test .region },
170
+ configName ,
171
+ test .statusCheckDeadlineSec )
143
172
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
144
173
deployer .useGcpOptions = false
145
174
manifestList , _ := json .Marshal (test .toDeploy )
@@ -311,7 +340,15 @@ func TestDeployJob(tOuter *testing.T) {
311
340
w .Write (b )
312
341
}))
313
342
314
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, configName )
343
+ deployer , _ := NewDeployer (
344
+ & runcontext.RunContext {},
345
+ & label.DefaultLabeller {},
346
+ & latest.CloudRunDeploy {
347
+ ProjectID : test .defaultProject ,
348
+ Region : test .region ,
349
+ },
350
+ configName ,
351
+ defaultStatusCheckDeadline )
315
352
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
316
353
deployer .useGcpOptions = false
317
354
manifestList , _ := k8syaml .Marshal (test .toDeploy )
@@ -469,7 +506,15 @@ func TestDeployRewrites(tOuter *testing.T) {
469
506
}
470
507
w .Write (b )
471
508
}))
472
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, "" )
509
+ deployer , _ := NewDeployer (
510
+ & runcontext.RunContext {},
511
+ & label.DefaultLabeller {},
512
+ & latest.CloudRunDeploy {
513
+ ProjectID : test .defaultProject ,
514
+ Region : test .region ,
515
+ },
516
+ "" ,
517
+ defaultStatusCheckDeadline )
473
518
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
474
519
deployer .useGcpOptions = false
475
520
m , _ := json .Marshal (test .toDeploy )
@@ -555,7 +600,15 @@ func TestCleanupService(tOuter *testing.T) {
555
600
w .Write (b )
556
601
}))
557
602
defer ts .Close ()
558
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, configName )
603
+ deployer , _ := NewDeployer (
604
+ & runcontext.RunContext {},
605
+ & label.DefaultLabeller {},
606
+ & latest.CloudRunDeploy {
607
+ ProjectID : test .defaultProject ,
608
+ Region : test .region ,
609
+ },
610
+ configName ,
611
+ defaultStatusCheckDeadline )
559
612
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
560
613
deployer .useGcpOptions = false
561
614
manifestListByConfig := manifest .NewManifestListByConfig ()
@@ -629,7 +682,15 @@ func TestCleanupJob(tOuter *testing.T) {
629
682
w .Write (b )
630
683
}))
631
684
defer ts .Close ()
632
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, configName )
685
+ deployer , _ := NewDeployer (
686
+ & runcontext.RunContext {},
687
+ & label.DefaultLabeller {},
688
+ & latest.CloudRunDeploy {
689
+ ProjectID : test .defaultProject ,
690
+ Region : test .region ,
691
+ },
692
+ configName ,
693
+ defaultStatusCheckDeadline )
633
694
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
634
695
deployer .useGcpOptions = false
635
696
manifestListByConfig := manifest .NewManifestListByConfig ()
@@ -693,7 +754,15 @@ func TestCleanupMultipleResources(tOuter *testing.T) {
693
754
w .Write (b )
694
755
}))
695
756
defer ts .Close ()
696
- deployer , _ := NewDeployer (& runcontext.RunContext {}, & label.DefaultLabeller {}, & latest.CloudRunDeploy {ProjectID : test .defaultProject , Region : test .region }, configName )
757
+ deployer , _ := NewDeployer (
758
+ & runcontext.RunContext {},
759
+ & label.DefaultLabeller {},
760
+ & latest.CloudRunDeploy {
761
+ ProjectID : test .defaultProject ,
762
+ Region : test .region ,
763
+ },
764
+ configName ,
765
+ defaultStatusCheckDeadline )
697
766
deployer .clientOptions = append (deployer .clientOptions , option .WithEndpoint (ts .URL ), option .WithoutAuthentication ())
698
767
deployer .useGcpOptions = false
699
768
manifestListByConfig := manifest .NewManifestListByConfig ()
0 commit comments