@@ -28,9 +28,83 @@ import (
28
28
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
29
29
pkgTest "github.com/knative/pkg/test"
30
30
"github.com/knative/pkg/test/logging"
31
+ "github.com/knative/serving/pkg/apis/serving/v1alpha1"
31
32
"github.com/knative/serving/test"
32
33
)
33
34
35
+ func TestBuildSpecAndServe (t * testing.T ) {
36
+ clients := Setup (t )
37
+
38
+ // Add test case specific name to its own logger.
39
+ logger := logging .GetContextLogger ("TestBuildAndServe" )
40
+
41
+ imagePath := test .ImagePath ("helloworld" )
42
+
43
+ logger .Infof ("Creating a new Route and Configuration with build" )
44
+ names := test.ResourceNames {
45
+ Config : test .AppendRandomString (configName , logger ),
46
+ Route : test .AppendRandomString (routeName , logger ),
47
+ }
48
+
49
+ build := & v1alpha1.RawExtension {
50
+ BuildSpec : & buildv1alpha1.BuildSpec {
51
+ Steps : []corev1.Container {{
52
+ Image : "ubuntu" ,
53
+ Args : []string {"echo" , "built" },
54
+ }},
55
+ },
56
+ }
57
+
58
+ if _ , err := clients .ServingClient .Configs .Create (test .ConfigurationWithBuild (test .ServingNamespace , names , build , imagePath )); err != nil {
59
+ t .Fatalf ("Failed to create Configuration: %v" , err )
60
+ }
61
+ if _ , err := clients .ServingClient .Routes .Create (test .Route (test .ServingNamespace , names )); err != nil {
62
+ t .Fatalf ("Failed to create Route: %v" , err )
63
+ }
64
+
65
+ test .CleanupOnInterrupt (func () { TearDown (clients , names , logger ) }, logger )
66
+ defer TearDown (clients , names , logger )
67
+
68
+ logger .Infof ("When the Revision can have traffic routed to it, the Route is marked as Ready." )
69
+ if err := test .WaitForRouteState (clients .ServingClient , names .Route , test .IsRouteReady , "RouteIsReady" ); err != nil {
70
+ t .Fatalf ("The Route %s was not marked as Ready to serve traffic: %v" , names .Route , err )
71
+ }
72
+
73
+ route , err := clients .ServingClient .Routes .Get (names .Route , metav1.GetOptions {})
74
+ if err != nil {
75
+ t .Fatalf ("Error fetching Route %s: %v" , names .Route , err )
76
+ }
77
+ domain := route .Status .Domain
78
+
79
+ endState := pkgTest .Retrying (pkgTest .MatchesBody (helloWorldExpectedOutput ), http .StatusNotFound )
80
+ if _ , err := pkgTest .WaitForEndpointState (clients .KubeClient , logger , domain , endState , "HelloWorldServesText" , test .ServingFlags .ResolvableDomain ); err != nil {
81
+ t .Fatalf ("The endpoint for Route %s at domain %s didn't serve the expected text \" %s\" : %v" , names .Route , domain , helloWorldExpectedOutput , err )
82
+ }
83
+
84
+ // Get Configuration's latest ready Revision's Build, and check that the Build was successful.
85
+ logger .Infof ("Revision is ready and serving, checking Build status." )
86
+ config , err := clients .ServingClient .Configs .Get (names .Config , metav1.GetOptions {})
87
+ if err != nil {
88
+ t .Fatalf ("Failed to get Configuration after it was seen to be live: %v" , err )
89
+ }
90
+ rev , err := clients .ServingClient .Revisions .Get (config .Status .LatestReadyRevisionName , metav1.GetOptions {})
91
+ if err != nil {
92
+ t .Fatalf ("Failed to get latest Revision: %v" , err )
93
+ }
94
+ buildName := rev .Spec .BuildName
95
+ logger .Infof ("Latest ready Revision is %q" , rev .Name )
96
+ logger .Infof ("Revision's Build is %q" , buildName )
97
+ b , err := clients .BuildClient .Builds .Get (buildName , metav1.GetOptions {})
98
+ if err != nil {
99
+ t .Fatalf ("Failed to get build for latest revision: %v" , err )
100
+ }
101
+ if cond := b .Status .GetCondition (buildv1alpha1 .BuildSucceeded ); cond == nil {
102
+ t .Fatalf ("Condition for build %q was nil" , buildName )
103
+ } else if cond .Status != corev1 .ConditionTrue {
104
+ t .Fatalf ("Build %q was not successful" , buildName )
105
+ }
106
+ }
107
+
34
108
func TestBuildAndServe (t * testing.T ) {
35
109
clients := Setup (t )
36
110
@@ -45,11 +119,19 @@ func TestBuildAndServe(t *testing.T) {
45
119
Route : test .AppendRandomString (routeName , logger ),
46
120
}
47
121
48
- build := & buildv1alpha1.BuildSpec {
49
- Steps : []corev1.Container {{
50
- Image : "ubuntu" ,
51
- Args : []string {"echo" , "built" },
52
- }},
122
+ build := & v1alpha1.RawExtension {
123
+ Object : & buildv1alpha1.Build {
124
+ TypeMeta : metav1.TypeMeta {
125
+ APIVersion : "build.knative.dev/v1alpha1" ,
126
+ Kind : "Build" ,
127
+ },
128
+ Spec : buildv1alpha1.BuildSpec {
129
+ Steps : []corev1.Container {{
130
+ Image : "ubuntu" ,
131
+ Args : []string {"echo" , "built" },
132
+ }},
133
+ },
134
+ },
53
135
}
54
136
55
137
if _ , err := clients .ServingClient .Configs .Create (test .ConfigurationWithBuild (test .ServingNamespace , names , build , imagePath )); err != nil {
@@ -114,11 +196,13 @@ func TestBuildFailure(t *testing.T) {
114
196
}
115
197
116
198
// Request a build that doesn't succeed.
117
- build := & buildv1alpha1.BuildSpec {
118
- Steps : []corev1.Container {{
119
- Image : "ubuntu" ,
120
- Args : []string {"false" }, // build will fail.
121
- }},
199
+ build := & v1alpha1.RawExtension {
200
+ BuildSpec : & buildv1alpha1.BuildSpec {
201
+ Steps : []corev1.Container {{
202
+ Image : "ubuntu" ,
203
+ Args : []string {"false" }, // build will fail.
204
+ }},
205
+ },
122
206
}
123
207
124
208
imagePath := test .ImagePath ("helloworld" )
0 commit comments