forked from barak/tarpoon
Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
28
vendor/k8s.io/kubernetes/pkg/util/flushwriter/BUILD
generated
vendored
Normal file
28
vendor/k8s.io/kubernetes/pkg/util/flushwriter/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"writer.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["writer_test.go"],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [],
|
||||
)
|
||||
19
vendor/k8s.io/kubernetes/pkg/util/flushwriter/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/util/flushwriter/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package flushwriter implements a wrapper for a writer that flushes on every
|
||||
// write if that writer implements the io.Flusher interface
|
||||
package flushwriter // import "k8s.io/kubernetes/pkg/util/flushwriter"
|
||||
53
vendor/k8s.io/kubernetes/pkg/util/flushwriter/writer.go
generated
vendored
Normal file
53
vendor/k8s.io/kubernetes/pkg/util/flushwriter/writer.go
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flushwriter
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Wrap wraps an io.Writer into a writer that flushes after every write if
|
||||
// the writer implements the Flusher interface.
|
||||
func Wrap(w io.Writer) io.Writer {
|
||||
fw := &flushWriter{
|
||||
writer: w,
|
||||
}
|
||||
if flusher, ok := w.(http.Flusher); ok {
|
||||
fw.flusher = flusher
|
||||
}
|
||||
return fw
|
||||
}
|
||||
|
||||
// flushWriter provides wrapper for responseWriter with HTTP streaming capabilities
|
||||
type flushWriter struct {
|
||||
flusher http.Flusher
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
// Write is a FlushWriter implementation of the io.Writer that sends any buffered
|
||||
// data to the client.
|
||||
func (fw *flushWriter) Write(p []byte) (n int, err error) {
|
||||
n, err = fw.writer.Write(p)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if fw.flusher != nil {
|
||||
fw.flusher.Flush()
|
||||
}
|
||||
return
|
||||
}
|
||||
86
vendor/k8s.io/kubernetes/pkg/util/flushwriter/writer_test.go
generated
vendored
Normal file
86
vendor/k8s.io/kubernetes/pkg/util/flushwriter/writer_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flushwriter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type writerWithFlush struct {
|
||||
writeCount, flushCount int
|
||||
err error
|
||||
}
|
||||
|
||||
func (w *writerWithFlush) Flush() {
|
||||
w.flushCount++
|
||||
}
|
||||
|
||||
func (w *writerWithFlush) Write(p []byte) (n int, err error) {
|
||||
w.writeCount++
|
||||
return len(p), w.err
|
||||
}
|
||||
|
||||
type writerWithNoFlush struct {
|
||||
writeCount int
|
||||
}
|
||||
|
||||
func (w *writerWithNoFlush) Write(p []byte) (n int, err error) {
|
||||
w.writeCount++
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func TestWriteWithFlush(t *testing.T) {
|
||||
w := &writerWithFlush{}
|
||||
fw := Wrap(w)
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := fw.Write([]byte("Test write"))
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error while writing with flush writer: %v", err)
|
||||
}
|
||||
}
|
||||
if w.flushCount != 10 {
|
||||
t.Errorf("Flush not called the expected number of times. Actual: %d", w.flushCount)
|
||||
}
|
||||
if w.writeCount != 10 {
|
||||
t.Errorf("Write not called the expected number of times. Actual: %d", w.writeCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteWithoutFlush(t *testing.T) {
|
||||
w := &writerWithNoFlush{}
|
||||
fw := Wrap(w)
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err := fw.Write([]byte("Test write"))
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error while writing with flush writer: %v", err)
|
||||
}
|
||||
}
|
||||
if w.writeCount != 10 {
|
||||
t.Errorf("Write not called the expected number of times. Actual: %d", w.writeCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteError(t *testing.T) {
|
||||
e := fmt.Errorf("Error")
|
||||
w := &writerWithFlush{err: e}
|
||||
fw := Wrap(w)
|
||||
_, err := fw.Write([]byte("Test write"))
|
||||
if err != e {
|
||||
t.Errorf("Did not get expected error. Got: %#v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue