vendor files

This commit is contained in:
Serguei Bezverkhi
2018-01-09 13:57:14 -05:00
parent 558bc6c02a
commit 7b24313bd6
16547 changed files with 4527373 additions and 0 deletions

36
vendor/k8s.io/kubernetes/pkg/util/limitwriter/BUILD generated vendored Normal file
View File

@ -0,0 +1,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"limitwriter.go",
],
importpath = "k8s.io/kubernetes/pkg/util/limitwriter",
)
go_test(
name = "go_default_test",
srcs = ["limitwriter_test.go"],
importpath = "k8s.io/kubernetes/pkg/util/limitwriter",
library = ":go_default_library",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

19
vendor/k8s.io/kubernetes/pkg/util/limitwriter/doc.go generated vendored Normal file
View File

@ -0,0 +1,19 @@
/*
Copyright 2015 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 limitwriter provides a writer that only allows a certain number of bytes to be
// written.
package limitwriter // import "k8s.io/kubernetes/pkg/util/limitwriter"

View File

@ -0,0 +1,53 @@
/*
Copyright 2015 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 limitwriter
import (
"errors"
"io"
)
// New creates a writer that is limited to writing at most n bytes to w. This writer is not
// thread safe.
func New(w io.Writer, n int64) io.Writer {
return &limitWriter{
w: w,
n: n,
}
}
// ErrMaximumWrite is returned when all bytes have been written.
var ErrMaximumWrite = errors.New("maximum write")
type limitWriter struct {
w io.Writer
n int64
}
func (w *limitWriter) Write(p []byte) (n int, err error) {
if int64(len(p)) > w.n {
p = p[:w.n]
}
if w.n > 0 {
n, err = w.w.Write(p)
w.n -= int64(n)
}
if w.n == 0 {
err = ErrMaximumWrite
}
return
}

View File

@ -0,0 +1,93 @@
/*
Copyright 2016 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 limitwriter
import (
"reflect"
"testing"
)
type recordingWriter struct {
Wrote [][]byte
}
func (r *recordingWriter) Write(data []byte) (int, error) {
r.Wrote = append(r.Wrote, data)
return len(data), nil
}
func TestLimitWriter(t *testing.T) {
testcases := map[string]struct {
Limit int64
Writes [][]byte
ExpectedRecordedWrites [][]byte
ExpectedReportedWrites []int
ExpectedReportedErrors []error
}{
"empty": {},
"empty write": {
Limit: 1000,
Writes: [][]byte{{}},
ExpectedRecordedWrites: [][]byte{{}},
ExpectedReportedWrites: []int{0},
ExpectedReportedErrors: []error{nil},
},
"unlimited write": {
Limit: 1000,
Writes: [][]byte{[]byte(`foo`)},
ExpectedRecordedWrites: [][]byte{[]byte(`foo`)},
ExpectedReportedWrites: []int{3},
ExpectedReportedErrors: []error{nil},
},
"limited write": {
Limit: 5,
Writes: [][]byte{[]byte(``), []byte(`1`), []byte(`23`), []byte(`456789`), []byte(`10`), []byte(``)},
ExpectedRecordedWrites: [][]byte{[]byte(``), []byte(`1`), []byte(`23`), []byte(`45`)},
ExpectedReportedWrites: []int{0, 1, 2, 2, 0, 0},
ExpectedReportedErrors: []error{nil, nil, nil, ErrMaximumWrite, ErrMaximumWrite, ErrMaximumWrite},
},
}
for k, tc := range testcases {
var reportedWrites []int
var reportedErrors []error
recordingWriter := &recordingWriter{}
limitwriter := New(recordingWriter, tc.Limit)
for _, w := range tc.Writes {
n, err := limitwriter.Write(w)
reportedWrites = append(reportedWrites, n)
reportedErrors = append(reportedErrors, err)
}
if !reflect.DeepEqual(recordingWriter.Wrote, tc.ExpectedRecordedWrites) {
t.Errorf("%s: expected recorded writes %v, got %v", k, tc.ExpectedRecordedWrites, recordingWriter.Wrote)
}
if !reflect.DeepEqual(reportedWrites, tc.ExpectedReportedWrites) {
t.Errorf("%s: expected reported writes %v, got %v", k, tc.ExpectedReportedWrites, reportedWrites)
}
if !reflect.DeepEqual(reportedErrors, tc.ExpectedReportedErrors) {
t.Errorf("%s: expected reported errors %v, got %v", k, tc.ExpectedReportedErrors, reportedErrors)
}
}
}