mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 02:07:58 +00:00
Add vendor folder to git
This commit is contained in:
parent
66cf5eaafb
commit
183585f56f
6916 changed files with 2629581 additions and 1 deletions
16
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/doc.go
generated
vendored
Normal file
16
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2015 Matt T. Proud
|
||||
//
|
||||
// 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 pbtest provides mechanisms to assist with testing of Protocol Buffer messages.
|
||||
package pbtest
|
||||
64
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/example_test.go
generated
vendored
Normal file
64
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/example_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// Copyright 2015 Matt T. Proud
|
||||
//
|
||||
// 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 pbtest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
// You would place this in a top-level function, like TestDatastore(t *testing.T).
|
||||
var (
|
||||
datastore Datastore
|
||||
t *testing.T
|
||||
)
|
||||
if err := quick.Check(func(rec *CustomerRecord) bool {
|
||||
// testing/quick generated rec using quick.Value. We want to ensure that
|
||||
// semi-internal struct fields are recursively reset to a known value.
|
||||
SanitizeGenerated(rec)
|
||||
// Ensure that any record can be stored, no matter what!
|
||||
if err := datastore.Store(rec); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Datastore models some system under test.
|
||||
type Datastore struct{}
|
||||
|
||||
// Store stores a customer record.
|
||||
func (Datastore) Store(*CustomerRecord) error { return nil }
|
||||
|
||||
// Types below are generated from protoc --go_out=. example.proto, where
|
||||
// example.proto contains
|
||||
// """
|
||||
// syntax = "proto2";
|
||||
// message CustomerRecord {
|
||||
// }
|
||||
// """
|
||||
|
||||
type CustomerRecord struct {
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *CustomerRecord) Reset() { *m = CustomerRecord{} }
|
||||
func (m *CustomerRecord) String() string { return proto.CompactTextString(m) }
|
||||
func (*CustomerRecord) ProtoMessage() {}
|
||||
78
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/quick.go
generated
vendored
Normal file
78
vendor/github.com/matttproud/golang_protobuf_extensions/pbtest/quick.go
generated
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// Copyright 2015 Matt T. Proud
|
||||
//
|
||||
// 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 pbtest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
errNotPointer = errors.New("pbtest: cannot sanitize non-pointer message")
|
||||
errNotStruct = errors.New("pbtest: cannot sanitize non-struct message")
|
||||
)
|
||||
|
||||
// SanitizeGenerated empties the private state fields of Protocol Buffer
|
||||
// messages that have been generated by the testing/quick package or returns
|
||||
// an error indicating a problem it encountered.
|
||||
func SanitizeGenerated(m proto.Message) error {
|
||||
return sanitizeGenerated(m, 0)
|
||||
}
|
||||
|
||||
func sanitizeGenerated(m proto.Message, l int) error {
|
||||
typ := reflect.TypeOf(m)
|
||||
if typ.Kind() != reflect.Ptr {
|
||||
if l == 0 {
|
||||
// Changes cannot be applied to non-pointers.
|
||||
return errNotPointer
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if elemTyp := typ.Elem(); elemTyp.Kind() != reflect.Struct {
|
||||
if l == 0 {
|
||||
// Protocol Buffer messages are structures; only they can be cleaned.
|
||||
return errNotStruct
|
||||
}
|
||||
return nil
|
||||
}
|
||||
elem := reflect.ValueOf(m).Elem()
|
||||
for i := 0; i < elem.NumField(); i++ {
|
||||
field := elem.Field(i)
|
||||
if field.Type().Implements(reflect.TypeOf((*proto.Message)(nil)).Elem()) {
|
||||
if err := sanitizeGenerated(field.Interface().(proto.Message), l+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if field.Kind() == reflect.Slice {
|
||||
for i := 0; i < field.Len(); i++ {
|
||||
elem := field.Index(i)
|
||||
if elem.Type().Implements(reflect.TypeOf((*proto.Message)(nil)).Elem()) {
|
||||
if err := sanitizeGenerated(elem.Interface().(proto.Message), l+1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if field := elem.FieldByName("XXX_unrecognized"); field.IsValid() {
|
||||
field.Set(reflect.ValueOf([]byte{}))
|
||||
}
|
||||
if field := elem.FieldByName("XXX_extensions"); field.IsValid() {
|
||||
field.Set(reflect.ValueOf(nil))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue