k8s.io/apiserver@v0.31.1/pkg/endpoints/responsewriter/fake.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package responsewriter
    18  
    19  import (
    20  	"bufio"
    21  	"net"
    22  	"net/http"
    23  )
    24  
    25  var _ http.ResponseWriter = &FakeResponseWriter{}
    26  
    27  // FakeResponseWriter implements http.ResponseWriter,
    28  // it is used for testing purpose only
    29  type FakeResponseWriter struct{}
    30  
    31  func (fw *FakeResponseWriter) Header() http.Header          { return http.Header{} }
    32  func (fw *FakeResponseWriter) WriteHeader(code int)         {}
    33  func (fw *FakeResponseWriter) Write(bs []byte) (int, error) { return len(bs), nil }
    34  
    35  // For HTTP2 an http.ResponseWriter object implements
    36  // http.Flusher and http.CloseNotifier.
    37  // It is used for testing purpose only
    38  type FakeResponseWriterFlusherCloseNotifier struct {
    39  	*FakeResponseWriter
    40  }
    41  
    42  func (fw *FakeResponseWriterFlusherCloseNotifier) Flush()                   {}
    43  func (fw *FakeResponseWriterFlusherCloseNotifier) CloseNotify() <-chan bool { return nil }
    44  
    45  // For HTTP/1.x an http.ResponseWriter object implements
    46  // http.Flusher, http.CloseNotifier and http.Hijacker.
    47  // It is used for testing purpose only
    48  type FakeResponseWriterFlusherCloseNotifierHijacker struct {
    49  	*FakeResponseWriterFlusherCloseNotifier
    50  }
    51  
    52  func (fw *FakeResponseWriterFlusherCloseNotifierHijacker) Hijack() (net.Conn, *bufio.ReadWriter, error) {
    53  	return nil, nil, nil
    54  }