@@ -17,14 +17,20 @@ limitations under the License.
17
17
package rest
18
18
19
19
import (
20
+ "fmt"
21
+ "strings"
20
22
"testing"
21
23
22
24
"k8s.io/apimachinery/pkg/api/errors"
23
25
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
24
26
"k8s.io/apiserver/pkg/registry/generic"
25
27
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
28
+ utilfeature "k8s.io/apiserver/pkg/util/feature"
29
+ featuregatetesting "k8s.io/component-base/featuregate/testing"
26
30
api "k8s.io/kubernetes/pkg/apis/core"
31
+ "k8s.io/kubernetes/pkg/features"
27
32
"k8s.io/kubernetes/pkg/registry/registrytest"
33
+ "k8s.io/utils/ptr"
28
34
)
29
35
30
36
func TestPodLogValidates (t * testing.T ) {
@@ -40,16 +46,86 @@ func TestPodLogValidates(t *testing.T) {
40
46
}
41
47
logRest := & LogREST {Store : store , KubeletConn : nil }
42
48
49
+ // This test will panic if you don't have a validation failure.
43
50
negativeOne := int64 (- 1 )
44
- testCases := []* api.PodLogOptions {
45
- {SinceSeconds : & negativeOne },
46
- {TailLines : & negativeOne },
51
+ testCases := []struct {
52
+ name string
53
+ podOptions api.PodLogOptions
54
+ podQueryLogOptions bool
55
+ invalidStreamMatch string
56
+ }{
57
+ {
58
+ name : "SinceSeconds" ,
59
+ podOptions : api.PodLogOptions {
60
+ SinceSeconds : & negativeOne ,
61
+ },
62
+ },
63
+ {
64
+ name : "TailLines" ,
65
+ podOptions : api.PodLogOptions {
66
+ TailLines : & negativeOne ,
67
+ },
68
+ },
69
+ {
70
+ name : "StreamWithGateOff" ,
71
+ podOptions : api.PodLogOptions {
72
+ SinceSeconds : & negativeOne ,
73
+ },
74
+ podQueryLogOptions : false ,
75
+ },
76
+ {
77
+ name : "StreamWithGateOnDefault" ,
78
+ podOptions : api.PodLogOptions {
79
+ SinceSeconds : & negativeOne ,
80
+ },
81
+ podQueryLogOptions : true ,
82
+ },
83
+ {
84
+ name : "StreamWithGateOnAll" ,
85
+ podOptions : api.PodLogOptions {
86
+ SinceSeconds : & negativeOne ,
87
+ Stream : ptr .To (api .LogStreamAll ),
88
+ },
89
+ podQueryLogOptions : true ,
90
+ },
91
+ {
92
+ name : "StreamWithGateOnStdErr" ,
93
+ podOptions : api.PodLogOptions {
94
+ SinceSeconds : & negativeOne ,
95
+ Stream : ptr .To (api .LogStreamStderr ),
96
+ },
97
+ podQueryLogOptions : true ,
98
+ },
99
+ {
100
+ name : "StreamWithGateOnStdOut" ,
101
+ podOptions : api.PodLogOptions {
102
+ SinceSeconds : & negativeOne ,
103
+ Stream : ptr .To (api .LogStreamStdout ),
104
+ },
105
+ podQueryLogOptions : true ,
106
+ },
107
+ {
108
+ name : "StreamWithGateOnAndBadValue" ,
109
+ podOptions : api.PodLogOptions {
110
+ Stream : ptr .To ("nostream" ),
111
+ },
112
+ podQueryLogOptions : true ,
113
+ invalidStreamMatch : "nostream" ,
114
+ },
47
115
}
48
116
49
117
for _ , tc := range testCases {
50
- _ , err := logRest .Get (genericapirequest .NewDefaultContext (), "test" , tc )
51
- if ! errors .IsInvalid (err ) {
52
- t .Fatalf ("Unexpected error: %v" , err )
53
- }
118
+ t .Run (tc .name , func (t * testing.T ) {
119
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodLogsQuerySplitStreams , tc .podQueryLogOptions )
120
+ _ , err := logRest .Get (genericapirequest .NewDefaultContext (), "test" , & tc .podOptions )
121
+ if ! errors .IsInvalid (err ) {
122
+ t .Fatalf ("Unexpected error: %v" , err )
123
+ }
124
+ if tc .invalidStreamMatch != "" {
125
+ if ! strings .Contains (err .Error (), "nostream" ) {
126
+ t .Error (fmt .Printf ("Expected %s got %s" , err .Error (), "nostream" ))
127
+ }
128
+ }
129
+ })
54
130
}
55
131
}
0 commit comments