diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-06-13 20:23:21 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-13 20:23:21 +0200 |
| commit | b41e96b421acda1761e9ba2ee17da16efad436cd (patch) | |
| tree | b6200bf1c3665161b6d76453bb56f7bd5ce32f42 /vendor/cloud.google.com/go/internal | |
| parent | f58147fb5ea43427d38c2a4437f35647138fbf9d (diff) | |
vendor: switch from dep to godep
dep tool vendored too much code (100MB) including tests and unused packages.
godep vendored significantly less (12MB) without tests and unused packages.
The main advantage is that pre-Go1.9 toolchain does not run tests
of all vendor packages now.
Diffstat (limited to 'vendor/cloud.google.com/go/internal')
33 files changed, 0 insertions, 3203 deletions
diff --git a/vendor/cloud.google.com/go/internal/atomiccache/atomiccache.go b/vendor/cloud.google.com/go/internal/atomiccache/atomiccache.go deleted file mode 100644 index 2bea8a150..000000000 --- a/vendor/cloud.google.com/go/internal/atomiccache/atomiccache.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 atomiccache provides a map-based cache that supports very fast -// reads. -package atomiccache - -import ( - "sync" - "sync/atomic" -) - -type mapType map[interface{}]interface{} - -// Cache is a map-based cache that supports fast reads via use of atomics. -// Writes are slow, requiring a copy of the entire cache. -// The zero Cache is an empty cache, ready for use. -type Cache struct { - val atomic.Value // mapType - mu sync.Mutex // used only by writers -} - -// Get returns the value of the cache at key. If there is no value, -// getter is called to provide one, and the cache is updated. -// The getter function may be called concurrently. It should be pure, -// returning the same value for every call. -func (c *Cache) Get(key interface{}, getter func() interface{}) interface{} { - mp, _ := c.val.Load().(mapType) - if v, ok := mp[key]; ok { - return v - } - - // Compute value without lock. - // Might duplicate effort but won't hold other computations back. - newV := getter() - - c.mu.Lock() - mp, _ = c.val.Load().(mapType) - newM := make(mapType, len(mp)+1) - for k, v := range mp { - newM[k] = v - } - newM[key] = newV - c.val.Store(newM) - c.mu.Unlock() - return newV -} diff --git a/vendor/cloud.google.com/go/internal/atomiccache/atomiccache_test.go b/vendor/cloud.google.com/go/internal/atomiccache/atomiccache_test.go deleted file mode 100644 index 33105b343..000000000 --- a/vendor/cloud.google.com/go/internal/atomiccache/atomiccache_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 atomiccache - -import ( - "fmt" - "testing" -) - -func TestGet(t *testing.T) { - var c Cache - called := false - get := func(k interface{}) interface{} { - return c.Get(k, func() interface{} { - called = true - return fmt.Sprintf("v%d", k) - }) - } - got := get(1) - if want := "v1"; got != want { - t.Errorf("got %v, want %v", got, want) - } - if !called { - t.Error("getter not called, expected a call") - } - called = false - got = get(1) - if want := "v1"; got != want { - t.Errorf("got %v, want %v", got, want) - } - if called { - t.Error("getter unexpectedly called") - } -} diff --git a/vendor/cloud.google.com/go/internal/fields/fields.go b/vendor/cloud.google.com/go/internal/fields/fields.go deleted file mode 100644 index 4f5516eae..000000000 --- a/vendor/cloud.google.com/go/internal/fields/fields.go +++ /dev/null @@ -1,444 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 fields provides a view of the fields of a struct that follows the Go -// rules, amended to consider tags and case insensitivity. -// -// Usage -// -// First define a function that interprets tags: -// -// func parseTag(st reflect.StructTag) (name string, keep bool, other interface{}, err error) { ... } -// -// The function's return values describe whether to ignore the field -// completely or provide an alternate name, as well as other data from the -// parse that is stored to avoid re-parsing. -// -// Then define a function to validate the type: -// -// func validate(t reflect.Type) error { ... } -// -// Then, if necessary, define a function to specify leaf types - types -// which should be considered one field and not be recursed into: -// -// func isLeafType(t reflect.Type) bool { ... } -// -// eg: -// -// func isLeafType(t reflect.Type) bool { -// return t == reflect.TypeOf(time.Time{}) -// } -// -// Next, construct a Cache, passing your functions. As its name suggests, a -// Cache remembers validation and field information for a type, so subsequent -// calls with the same type are very fast. -// -// cache := fields.NewCache(parseTag, validate, isLeafType) -// -// To get the fields of a struct type as determined by the above rules, call -// the Fields method: -// -// fields, err := cache.Fields(reflect.TypeOf(MyStruct{})) -// -// The return value can be treated as a slice of Fields. -// -// Given a string, such as a key or column name obtained during unmarshalling, -// call Match on the list of fields to find a field whose name is the best -// match: -// -// field := fields.Match(name) -// -// Match looks for an exact match first, then falls back to a case-insensitive -// comparison. -package fields - -import ( - "bytes" - "reflect" - "sort" - - "cloud.google.com/go/internal/atomiccache" -) - -// A Field records information about a struct field. -type Field struct { - Name string // effective field name - NameFromTag bool // did Name come from a tag? - Type reflect.Type // field type - Index []int // index sequence, for reflect.Value.FieldByIndex - ParsedTag interface{} // third return value of the parseTag function - - nameBytes []byte - equalFold func(s, t []byte) bool -} - -type ParseTagFunc func(reflect.StructTag) (name string, keep bool, other interface{}, err error) - -type ValidateFunc func(reflect.Type) error - -type LeafTypesFunc func(reflect.Type) bool - -// A Cache records information about the fields of struct types. -// -// A Cache is safe for use by multiple goroutines. -type Cache struct { - parseTag ParseTagFunc - validate ValidateFunc - leafTypes LeafTypesFunc - cache atomiccache.Cache // from reflect.Type to cacheValue -} - -// NewCache constructs a Cache. -// -// Its first argument should be a function that accepts -// a struct tag and returns four values: an alternative name for the field -// extracted from the tag, a boolean saying whether to keep the field or ignore -// it, additional data that is stored with the field information to avoid -// having to parse the tag again, and an error. -// -// Its second argument should be a function that accepts a reflect.Type and -// returns an error if the struct type is invalid in any way. For example, it -// may check that all of the struct field tags are valid, or that all fields -// are of an appropriate type. -func NewCache(parseTag ParseTagFunc, validate ValidateFunc, leafTypes LeafTypesFunc) *Cache { - if parseTag == nil { - parseTag = func(reflect.StructTag) (string, bool, interface{}, error) { - return "", true, nil, nil - } - } - if validate == nil { - validate = func(reflect.Type) error { - return nil - } - } - if leafTypes == nil { - leafTypes = func(reflect.Type) bool { - return false - } - } - - return &Cache{ - parseTag: parseTag, - validate: validate, - leafTypes: leafTypes, - } -} - -// A fieldScan represents an item on the fieldByNameFunc scan work list. -type fieldScan struct { - typ reflect.Type - index []int -} - -// Fields returns all the exported fields of t, which must be a struct type. It -// follows the standard Go rules for embedded fields, modified by the presence -// of tags. The result is sorted lexicographically by index. -// -// These rules apply in the absence of tags: -// Anonymous struct fields are treated as if their inner exported fields were -// fields in the outer struct (embedding). The result includes all fields that -// aren't shadowed by fields at higher level of embedding. If more than one -// field with the same name exists at the same level of embedding, it is -// excluded. An anonymous field that is not of struct type is treated as having -// its type as its name. -// -// Tags modify these rules as follows: -// A field's tag is used as its name. -// An anonymous struct field with a name given in its tag is treated as -// a field having that name, rather than an embedded struct (the struct's -// fields will not be returned). -// If more than one field with the same name exists at the same level of embedding, -// but exactly one of them is tagged, then the tagged field is reported and the others -// are ignored. -func (c *Cache) Fields(t reflect.Type) (List, error) { - if t.Kind() != reflect.Struct { - panic("fields: Fields of non-struct type") - } - return c.cachedTypeFields(t) -} - -// A List is a list of Fields. -type List []Field - -// Match returns the field in the list whose name best matches the supplied -// name, nor nil if no field does. If there is a field with the exact name, it -// is returned. Otherwise the first field (sorted by index) whose name matches -// case-insensitively is returned. -func (l List) Match(name string) *Field { - return l.MatchBytes([]byte(name)) -} - -// MatchBytes is identical to Match, except that the argument is a byte slice. -func (l List) MatchBytes(name []byte) *Field { - var f *Field - for i := range l { - ff := &l[i] - if bytes.Equal(ff.nameBytes, name) { - return ff - } - if f == nil && ff.equalFold(ff.nameBytes, name) { - f = ff - } - } - return f -} - -type cacheValue struct { - fields List - err error -} - -// cachedTypeFields is like typeFields but uses a cache to avoid repeated work. -// This code has been copied and modified from -// https://go.googlesource.com/go/+/go1.7.3/src/encoding/json/encode.go. -func (c *Cache) cachedTypeFields(t reflect.Type) (List, error) { - cv := c.cache.Get(t, func() interface{} { - if err := c.validate(t); err != nil { - return cacheValue{nil, err} - } - f, err := c.typeFields(t) - return cacheValue{List(f), err} - }).(cacheValue) - return cv.fields, cv.err -} - -func (c *Cache) typeFields(t reflect.Type) ([]Field, error) { - fields, err := c.listFields(t) - if err != nil { - return nil, err - } - sort.Sort(byName(fields)) - // Delete all fields that are hidden by the Go rules for embedded fields. - - // The fields are sorted in primary order of name, secondary order of field - // index length. So the first field with a given name is the dominant one. - var out []Field - for advance, i := 0, 0; i < len(fields); i += advance { - // One iteration per name. - // Find the sequence of fields with the name of this first field. - fi := fields[i] - name := fi.Name - for advance = 1; i+advance < len(fields); advance++ { - fj := fields[i+advance] - if fj.Name != name { - break - } - } - // Find the dominant field, if any, out of all fields that have the same name. - dominant, ok := dominantField(fields[i : i+advance]) - if ok { - out = append(out, dominant) - } - } - sort.Sort(byIndex(out)) - return out, nil -} - -func (c *Cache) listFields(t reflect.Type) ([]Field, error) { - // This uses the same condition that the Go language does: there must be a unique instance - // of the match at a given depth level. If there are multiple instances of a match at the - // same depth, they annihilate each other and inhibit any possible match at a lower level. - // The algorithm is breadth first search, one depth level at a time. - - // The current and next slices are work queues: - // current lists the fields to visit on this depth level, - // and next lists the fields on the next lower level. - current := []fieldScan{} - next := []fieldScan{{typ: t}} - - // nextCount records the number of times an embedded type has been - // encountered and considered for queueing in the 'next' slice. - // We only queue the first one, but we increment the count on each. - // If a struct type T can be reached more than once at a given depth level, - // then it annihilates itself and need not be considered at all when we - // process that next depth level. - var nextCount map[reflect.Type]int - - // visited records the structs that have been considered already. - // Embedded pointer fields can create cycles in the graph of - // reachable embedded types; visited avoids following those cycles. - // It also avoids duplicated effort: if we didn't find the field in an - // embedded type T at level 2, we won't find it in one at level 4 either. - visited := map[reflect.Type]bool{} - - var fields []Field // Fields found. - - for len(next) > 0 { - current, next = next, current[:0] - count := nextCount - nextCount = nil - - // Process all the fields at this depth, now listed in 'current'. - // The loop queues embedded fields found in 'next', for processing during the next - // iteration. The multiplicity of the 'current' field counts is recorded - // in 'count'; the multiplicity of the 'next' field counts is recorded in 'nextCount'. - for _, scan := range current { - t := scan.typ - if visited[t] { - // We've looked through this type before, at a higher level. - // That higher level would shadow the lower level we're now at, - // so this one can't be useful to us. Ignore it. - continue - } - visited[t] = true - for i := 0; i < t.NumField(); i++ { - f := t.Field(i) - - exported := (f.PkgPath == "") - - // If a named field is unexported, ignore it. An anonymous - // unexported field is processed, because it may contain - // exported fields, which are visible. - if !exported && !f.Anonymous { - continue - } - - // Examine the tag. - tagName, keep, other, err := c.parseTag(f.Tag) - if err != nil { - return nil, err - } - if !keep { - continue - } - if c.leafTypes(f.Type) { - fields = append(fields, newField(f, tagName, other, scan.index, i)) - continue - } - - var ntyp reflect.Type - if f.Anonymous { - // Anonymous field of type T or *T. - ntyp = f.Type - if ntyp.Kind() == reflect.Ptr { - ntyp = ntyp.Elem() - } - } - - // Record fields with a tag name, non-anonymous fields, or - // anonymous non-struct fields. - if tagName != "" || ntyp == nil || ntyp.Kind() != reflect.Struct { - if !exported { - continue - } - fields = append(fields, newField(f, tagName, other, scan.index, i)) - if count[t] > 1 { - // If there were multiple instances, add a second, - // so that the annihilation code will see a duplicate. - fields = append(fields, fields[len(fields)-1]) - } - continue - } - - // Queue embedded struct fields for processing with next level, - // but only if the embedded types haven't already been queued. - if nextCount[ntyp] > 0 { - nextCount[ntyp] = 2 // exact multiple doesn't matter - continue - } - if nextCount == nil { - nextCount = map[reflect.Type]int{} - } - nextCount[ntyp] = 1 - if count[t] > 1 { - nextCount[ntyp] = 2 // exact multiple doesn't matter - } - var index []int - index = append(index, scan.index...) - index = append(index, i) - next = append(next, fieldScan{ntyp, index}) - } - } - } - return fields, nil -} - -func newField(f reflect.StructField, tagName string, other interface{}, index []int, i int) Field { - name := tagName - if name == "" { - name = f.Name - } - sf := Field{ - Name: name, - NameFromTag: tagName != "", - Type: f.Type, - ParsedTag: other, - nameBytes: []byte(name), - } - sf.equalFold = foldFunc(sf.nameBytes) - sf.Index = append(sf.Index, index...) - sf.Index = append(sf.Index, i) - return sf -} - -// byName sorts fields using the following criteria, in order: -// 1. name -// 2. embedding depth -// 3. tag presence (preferring a tagged field) -// 4. index sequence. -type byName []Field - -func (x byName) Len() int { return len(x) } - -func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] } - -func (x byName) Less(i, j int) bool { - if x[i].Name != x[j].Name { - return x[i].Name < x[j].Name - } - if len(x[i].Index) != len(x[j].Index) { - return len(x[i].Index) < len(x[j].Index) - } - if x[i].NameFromTag != x[j].NameFromTag { - return x[i].NameFromTag - } - return byIndex(x).Less(i, j) -} - -// byIndex sorts field by index sequence. -type byIndex []Field - -func (x byIndex) Len() int { return len(x) } - -func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] } - -func (x byIndex) Less(i, j int) bool { - xi := x[i].Index - xj := x[j].Index - ln := len(xi) - if l := len(xj); l < ln { - ln = l - } - for k := 0; k < ln; k++ { - if xi[k] != xj[k] { - return xi[k] < xj[k] - } - } - return len(xi) < len(xj) -} - -// dominantField looks through the fields, all of which are known to have the -// same name, to find the single field that dominates the others using Go's -// embedding rules, modified by the presence of tags. If there are multiple -// top-level fields, the boolean will be false: This condition is an error in -// Go and we skip all the fields. -func dominantField(fs []Field) (Field, bool) { - // The fields are sorted in increasing index-length order, then by presence of tag. - // That means that the first field is the dominant one. We need only check - // for error cases: two fields at top level, either both tagged or neither tagged. - if len(fs) > 1 && len(fs[0].Index) == len(fs[1].Index) && fs[0].NameFromTag == fs[1].NameFromTag { - return Field{}, false - } - return fs[0], true -} diff --git a/vendor/cloud.google.com/go/internal/fields/fields_test.go b/vendor/cloud.google.com/go/internal/fields/fields_test.go deleted file mode 100644 index 904d8b855..000000000 --- a/vendor/cloud.google.com/go/internal/fields/fields_test.go +++ /dev/null @@ -1,561 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 fields - -import ( - "encoding/json" - "errors" - "fmt" - "reflect" - "strings" - "testing" - "time" -) - -type embed1 struct { - Em1 int - Dup int // annihilates with embed2.Dup - Shadow int - embed3 -} - -type embed2 struct { - Dup int - embed3 - embed4 -} - -type embed3 struct { - Em3 int // annihilated because embed3 is in both embed1 and embed2 - embed5 -} - -type embed4 struct { - Em4 int - Dup int // annihilation of Dup in embed1, embed2 hides this Dup - *embed1 // ignored because it occurs at a higher level -} - -type embed5 struct { - x int -} - -type Anonymous int - -type S1 struct { - Exported int - unexported int - Shadow int // shadows S1.Shadow - embed1 - *embed2 - Anonymous -} - -type Time struct { - time.Time -} - -var intType = reflect.TypeOf(int(0)) - -func field(name string, tval interface{}, index ...int) *Field { - return &Field{ - Name: name, - Type: reflect.TypeOf(tval), - Index: index, - } -} - -func tfield(name string, tval interface{}, index ...int) *Field { - return &Field{ - Name: name, - Type: reflect.TypeOf(tval), - Index: index, - NameFromTag: true, - } -} - -func TestFieldsNoTags(t *testing.T) { - c := NewCache(nil, nil, nil) - got, err := c.Fields(reflect.TypeOf(S1{})) - if err != nil { - t.Fatal(err) - } - want := []*Field{ - field("Exported", int(0), 0), - field("Shadow", int(0), 2), - field("Em1", int(0), 3, 0), - field("Em4", int(0), 4, 2, 0), - field("Anonymous", Anonymous(0), 5), - } - if msg, ok := compareFields(got, want); !ok { - t.Error(msg) - } -} - -func TestAgainstJSONEncodingNoTags(t *testing.T) { - // Demonstrates that this package produces the same set of fields as encoding/json. - s1 := S1{ - Exported: 1, - unexported: 2, - Shadow: 3, - embed1: embed1{ - Em1: 4, - Dup: 5, - Shadow: 6, - embed3: embed3{ - Em3: 7, - embed5: embed5{x: 8}, - }, - }, - embed2: &embed2{ - Dup: 9, - embed3: embed3{ - Em3: 10, - embed5: embed5{x: 11}, - }, - embed4: embed4{ - Em4: 12, - Dup: 13, - embed1: &embed1{Em1: 14}, - }, - }, - Anonymous: Anonymous(15), - } - var want S1 - jsonRoundTrip(t, s1, &want) - var got S1 - got.embed2 = &embed2{} // need this because reflection won't create it - fields, err := NewCache(nil, nil, nil).Fields(reflect.TypeOf(got)) - if err != nil { - t.Fatal(err) - } - setFields(fields, &got, s1) - if !reflect.DeepEqual(got, want) { - t.Errorf("got\n%+v\nwant\n%+v", got, want) - } -} - -// Tests use of LeafTypes parameter to NewCache -func TestAgainstJSONEncodingEmbeddedTime(t *testing.T) { - timeLeafFn := func(t reflect.Type) bool { - return t == reflect.TypeOf(time.Time{}) - } - // Demonstrates that this package can produce the same set of - // fields as encoding/json for a struct with an embedded time.Time. - now := time.Now().UTC() - myt := Time{ - now, - } - var want Time - jsonRoundTrip(t, myt, &want) - var got Time - fields, err := NewCache(nil, nil, timeLeafFn).Fields(reflect.TypeOf(got)) - if err != nil { - t.Fatal(err) - } - setFields(fields, &got, myt) - if !reflect.DeepEqual(got, want) { - t.Errorf("got\n%+v\nwant\n%+v", got, want) - } -} - -type S2 struct { - NoTag int - XXX int `json:"tag"` // tag name takes precedence - Anonymous `json:"anon"` // anonymous non-structs also get their name from the tag - unexported int `json:"tag"` - Embed `json:"em"` // embedded structs with tags become fields - Tag int - YYY int `json:"Tag"` // tag takes precedence over untagged field of the same name - Empty int `json:""` // empty tag is noop - tEmbed1 - tEmbed2 -} - -type Embed struct { - Em int -} - -type tEmbed1 struct { - Dup int - X int `json:"Dup2"` -} - -type tEmbed2 struct { - Y int `json:"Dup"` // takes precedence over tEmbed1.Dup because it is tagged - Z int `json:"Dup2"` // same name as tEmbed1.X and both tagged, so ignored -} - -func jsonTagParser(t reflect.StructTag) (name string, keep bool, other interface{}, err error) { - s := t.Get("json") - parts := strings.Split(s, ",") - if parts[0] == "-" { - return "", false, nil, nil - } - if len(parts) > 1 { - other = parts[1:] - } - return parts[0], true, other, nil -} - -func validateFunc(t reflect.Type) (err error) { - if t.Kind() != reflect.Struct { - return errors.New("non-struct type used") - } - - for i := 0; i < t.NumField(); i++ { - if t.Field(i).Type.Kind() == reflect.Slice { - return fmt.Errorf("slice field found at field %s on struct %s", t.Field(i).Name, t.Name()) - } - } - - return nil -} - -func TestFieldsWithTags(t *testing.T) { - got, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S2{})) - if err != nil { - t.Fatal(err) - } - want := []*Field{ - field("NoTag", int(0), 0), - tfield("tag", int(0), 1), - tfield("anon", Anonymous(0), 2), - tfield("em", Embed{}, 4), - tfield("Tag", int(0), 6), - field("Empty", int(0), 7), - tfield("Dup", int(0), 8, 0), - } - if msg, ok := compareFields(got, want); !ok { - t.Error(msg) - } -} - -func TestAgainstJSONEncodingWithTags(t *testing.T) { - // Demonstrates that this package produces the same set of fields as encoding/json. - s2 := S2{ - NoTag: 1, - XXX: 2, - Anonymous: 3, - Embed: Embed{ - Em: 4, - }, - tEmbed1: tEmbed1{ - Dup: 5, - X: 6, - }, - tEmbed2: tEmbed2{ - Y: 7, - Z: 8, - }, - } - var want S2 - jsonRoundTrip(t, s2, &want) - var got S2 - fields, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(got)) - if err != nil { - t.Fatal(err) - } - setFields(fields, &got, s2) - if !reflect.DeepEqual(got, want) { - t.Errorf("got\n%+v\nwant\n%+v", got, want) - } -} - -func TestUnexportedAnonymousNonStruct(t *testing.T) { - // An unexported anonymous non-struct field should not be recorded. - // This is currently a bug in encoding/json. - // https://github.com/golang/go/issues/18009 - type ( - u int - v int - S struct { - u - v `json:"x"` - int - } - ) - - got, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S{})) - if err != nil { - t.Fatal(err) - } - if len(got) != 0 { - t.Errorf("got %d fields, want 0", len(got)) - } -} - -func TestUnexportedAnonymousStruct(t *testing.T) { - // An unexported anonymous struct with a tag is ignored. - // This is currently a bug in encoding/json. - // https://github.com/golang/go/issues/18009 - type ( - s1 struct{ X int } - S2 struct { - s1 `json:"Y"` - } - ) - got, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S2{})) - if err != nil { - t.Fatal(err) - } - if len(got) != 0 { - t.Errorf("got %d fields, want 0", len(got)) - } -} - -func TestDominantField(t *testing.T) { - // With fields sorted by index length and then by tag presence, - // the dominant field is always the first. Make sure all error - // cases are caught. - for _, test := range []struct { - fields []Field - wantOK bool - }{ - // A single field is OK. - {[]Field{{Index: []int{0}}}, true}, - {[]Field{{Index: []int{0}, NameFromTag: true}}, true}, - // A single field at top level is OK. - {[]Field{{Index: []int{0}}, {Index: []int{1, 0}}}, true}, - {[]Field{{Index: []int{0}}, {Index: []int{1, 0}, NameFromTag: true}}, true}, - {[]Field{{Index: []int{0}, NameFromTag: true}, {Index: []int{1, 0}, NameFromTag: true}}, true}, - // A single tagged field is OK. - {[]Field{{Index: []int{0}, NameFromTag: true}, {Index: []int{1}}}, true}, - // Two untagged fields at the same level is an error. - {[]Field{{Index: []int{0}}, {Index: []int{1}}}, false}, - // Two tagged fields at the same level is an error. - {[]Field{{Index: []int{0}, NameFromTag: true}, {Index: []int{1}, NameFromTag: true}}, false}, - } { - _, gotOK := dominantField(test.fields) - if gotOK != test.wantOK { - t.Errorf("%v: got %t, want %t", test.fields, gotOK, test.wantOK) - } - } -} - -func TestIgnore(t *testing.T) { - type S struct { - X int `json:"-"` - } - got, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S{})) - if err != nil { - t.Fatal(err) - } - if len(got) != 0 { - t.Errorf("got %d fields, want 0", len(got)) - } -} - -func TestParsedTag(t *testing.T) { - type S struct { - X int `json:"name,omitempty"` - } - got, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S{})) - if err != nil { - t.Fatal(err) - } - want := []*Field{ - {Name: "name", NameFromTag: true, Type: intType, - Index: []int{0}, ParsedTag: []string{"omitempty"}}, - } - if msg, ok := compareFields(got, want); !ok { - t.Error(msg) - } -} - -func TestValidateFunc(t *testing.T) { - type MyInvalidStruct struct { - A string - B []int - } - - _, err := NewCache(nil, validateFunc, nil).Fields(reflect.TypeOf(MyInvalidStruct{})) - if err == nil { - t.Fatal("expected error, got nil") - } - - type MyValidStruct struct { - A string - B int - } - _, err = NewCache(nil, validateFunc, nil).Fields(reflect.TypeOf(MyValidStruct{})) - if err != nil { - t.Fatalf("expected nil, got error: %s\n", err) - } -} - -func compareFields(got []Field, want []*Field) (msg string, ok bool) { - if len(got) != len(want) { - return fmt.Sprintf("got %d fields, want %d", len(got), len(want)), false - } - for i, g := range got { - w := *want[i] - if !fieldsEqual(&g, &w) { - return fmt.Sprintf("got %+v, want %+v", g, w), false - } - } - return "", true -} - -// Need this because Field contains a function, which cannot be compared even -// by reflect.DeepEqual. -func fieldsEqual(f1, f2 *Field) bool { - if f1 == nil || f2 == nil { - return f1 == f2 - } - return f1.Name == f2.Name && - f1.NameFromTag == f2.NameFromTag && - f1.Type == f2.Type && - reflect.DeepEqual(f1.ParsedTag, f2.ParsedTag) -} - -// Set the fields of dst from those of src. -// dst must be a pointer to a struct value. -// src must be a struct value. -func setFields(fields []Field, dst, src interface{}) { - vsrc := reflect.ValueOf(src) - vdst := reflect.ValueOf(dst).Elem() - for _, f := range fields { - fdst := vdst.FieldByIndex(f.Index) - fsrc := vsrc.FieldByIndex(f.Index) - fdst.Set(fsrc) - } -} - -func jsonRoundTrip(t *testing.T, in, out interface{}) { - bytes, err := json.Marshal(in) - if err != nil { - t.Fatal(err) - } - if err := json.Unmarshal(bytes, out); err != nil { - t.Fatal(err) - } -} - -type S3 struct { - S4 - Abc int - AbC int - Tag int - X int `json:"Tag"` - unexported int -} - -type S4 struct { - ABc int - Y int `json:"Abc"` // ignored because of top-level Abc -} - -func TestMatchingField(t *testing.T) { - fields, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S3{})) - if err != nil { - t.Fatal(err) - } - for _, test := range []struct { - name string - want *Field - }{ - // Exact match wins. - {"Abc", field("Abc", int(0), 1)}, - {"AbC", field("AbC", int(0), 2)}, - {"ABc", field("ABc", int(0), 0, 0)}, - // If there are multiple matches but no exact match or tag, - // the first field wins, lexicographically by index. - // Here, "ABc" is at a deeper embedding level, but since S4 appears - // first in S3, its index precedes the other fields of S3. - {"abc", field("ABc", int(0), 0, 0)}, - // Tag name takes precedence over untagged field of the same name. - {"Tag", tfield("Tag", int(0), 4)}, - // Unexported fields disappear. - {"unexported", nil}, - // Untagged embedded structs disappear. - {"S4", nil}, - } { - if got := fields.Match(test.name); !fieldsEqual(got, test.want) { - t.Errorf("match %q:\ngot %+v\nwant %+v", test.name, got, test.want) - } - } -} - -func TestAgainstJSONMatchingField(t *testing.T) { - s3 := S3{ - S4: S4{ABc: 1, Y: 2}, - Abc: 3, - AbC: 4, - Tag: 5, - X: 6, - unexported: 7, - } - var want S3 - jsonRoundTrip(t, s3, &want) - v := reflect.ValueOf(want) - fields, err := NewCache(jsonTagParser, nil, nil).Fields(reflect.TypeOf(S3{})) - if err != nil { - t.Fatal(err) - } - for _, test := range []struct { - name string - got int - }{ - {"Abc", 3}, - {"AbC", 4}, - {"ABc", 1}, - {"abc", 1}, - {"Tag", 6}, - } { - f := fields.Match(test.name) - if f == nil { - t.Fatalf("%s: no match", test.name) - } - w := v.FieldByIndex(f.Index).Interface() - if test.got != w { - t.Errorf("%s: got %d, want %d", test.name, test.got, w) - } - } -} - -func TestTagErrors(t *testing.T) { - called := false - c := NewCache(func(t reflect.StructTag) (string, bool, interface{}, error) { - called = true - s := t.Get("f") - if s == "bad" { - return "", false, nil, errors.New("error") - } - return s, true, nil, nil - }, nil, nil) - - type T struct { - X int `f:"ok"` - Y int `f:"bad"` - } - - _, err := c.Fields(reflect.TypeOf(T{})) - if !called { - t.Fatal("tag parser not called") - } - if err == nil { - t.Error("want error, got nil") - } - // Second time, we should cache the error. - called = false - _, err = c.Fields(reflect.TypeOf(T{})) - if called { - t.Fatal("tag parser called on second time") - } - if err == nil { - t.Error("want error, got nil") - } -} diff --git a/vendor/cloud.google.com/go/internal/fields/fold.go b/vendor/cloud.google.com/go/internal/fields/fold.go deleted file mode 100644 index 10a68189c..000000000 --- a/vendor/cloud.google.com/go/internal/fields/fold.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 fields - -// This file was copied from https://go.googlesource.com/go/+/go1.7.3/src/encoding/json/fold.go. -// Only the license and package were changed. - -import ( - "bytes" - "unicode/utf8" -) - -const ( - caseMask = ^byte(0x20) // Mask to ignore case in ASCII. - kelvin = '\u212a' - smallLongEss = '\u017f' -) - -// foldFunc returns one of four different case folding equivalence -// functions, from most general (and slow) to fastest: -// -// 1) bytes.EqualFold, if the key s contains any non-ASCII UTF-8 -// 2) equalFoldRight, if s contains special folding ASCII ('k', 'K', 's', 'S') -// 3) asciiEqualFold, no special, but includes non-letters (including _) -// 4) simpleLetterEqualFold, no specials, no non-letters. -// -// The letters S and K are special because they map to 3 runes, not just 2: -// * S maps to s and to U+017F 'ſ' Latin small letter long s -// * k maps to K and to U+212A 'K' Kelvin sign -// See https://play.golang.org/p/tTxjOc0OGo -// -// The returned function is specialized for matching against s and -// should only be given s. It's not curried for performance reasons. -func foldFunc(s []byte) func(s, t []byte) bool { - nonLetter := false - special := false // special letter - for _, b := range s { - if b >= utf8.RuneSelf { - return bytes.EqualFold - } - upper := b & caseMask - if upper < 'A' || upper > 'Z' { - nonLetter = true - } else if upper == 'K' || upper == 'S' { - // See above for why these letters are special. - special = true - } - } - if special { - return equalFoldRight - } - if nonLetter { - return asciiEqualFold - } - return simpleLetterEqualFold -} - -// equalFoldRight is a specialization of bytes.EqualFold when s is -// known to be all ASCII (including punctuation), but contains an 's', -// 'S', 'k', or 'K', requiring a Unicode fold on the bytes in t. -// See comments on foldFunc. -func equalFoldRight(s, t []byte) bool { - for _, sb := range s { - if len(t) == 0 { - return false - } - tb := t[0] - if tb < utf8.RuneSelf { - if sb != tb { - sbUpper := sb & caseMask - if 'A' <= sbUpper && sbUpper <= 'Z' { - if sbUpper != tb&caseMask { - return false - } - } else { - return false - } - } - t = t[1:] - continue - } - // sb is ASCII and t is not. t must be either kelvin - // sign or long s; sb must be s, S, k, or K. - tr, size := utf8.DecodeRune(t) - switch sb { - case 's', 'S': - if tr != smallLongEss { - return false - } - case 'k', 'K': - if tr != kelvin { - return false - } - default: - return false - } - t = t[size:] - - } - if len(t) > 0 { - return false - } - return true -} - -// asciiEqualFold is a specialization of bytes.EqualFold for use when -// s is all ASCII (but may contain non-letters) and contains no -// special-folding letters. -// See comments on foldFunc. -func asciiEqualFold(s, t []byte) bool { - if len(s) != len(t) { - return false - } - for i, sb := range s { - tb := t[i] - if sb == tb { - continue - } - if ('a' <= sb && sb <= 'z') || ('A' <= sb && sb <= 'Z') { - if sb&caseMask != tb&caseMask { - return false - } - } else { - return false - } - } - return true -} - -// simpleLetterEqualFold is a specialization of bytes.EqualFold for -// use when s is all ASCII letters (no underscores, etc) and also -// doesn't contain 'k', 'K', 's', or 'S'. -// See comments on foldFunc. -func simpleLetterEqualFold(s, t []byte) bool { - if len(s) != len(t) { - return false - } - for i, b := range s { - if b&caseMask != t[i]&caseMask { - return false - } - } - return true -} diff --git a/vendor/cloud.google.com/go/internal/fields/fold_test.go b/vendor/cloud.google.com/go/internal/fields/fold_test.go deleted file mode 100644 index eadded18d..000000000 --- a/vendor/cloud.google.com/go/internal/fields/fold_test.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 fields - -// This file was copied from https://go.googlesource.com/go/+/go1.7.3/src/encoding/json/fold_test.go. -// Only the license and package were changed. - -import ( - "bytes" - "strings" - "testing" - "unicode/utf8" -) - -var foldTests = []struct { - fn func(s, t []byte) bool - s, t string - want bool -}{ - {equalFoldRight, "", "", true}, - {equalFoldRight, "a", "a", true}, - {equalFoldRight, "", "a", false}, - {equalFoldRight, "a", "", false}, - {equalFoldRight, "a", "A", true}, - {equalFoldRight, "AB", "ab", true}, - {equalFoldRight, "AB", "ac", false}, - {equalFoldRight, "sbkKc", "ſbKKc", true}, - {equalFoldRight, "SbKkc", "ſbKKc", true}, - {equalFoldRight, "SbKkc", "ſbKK", false}, - {equalFoldRight, "e", "é", false}, - {equalFoldRight, "s", "S", true}, - - {simpleLetterEqualFold, "", "", true}, - {simpleLetterEqualFold, "abc", "abc", true}, - {simpleLetterEqualFold, "abc", "ABC", true}, - {simpleLetterEqualFold, "abc", "ABCD", false}, - {simpleLetterEqualFold, "abc", "xxx", false}, - - {asciiEqualFold, "a_B", "A_b", true}, - {asciiEqualFold, "aa@", "aa`", false}, // verify 0x40 and 0x60 aren't case-equivalent -} - -func TestFold(t *testing.T) { - for i, tt := range foldTests { - if got := tt.fn([]byte(tt.s), []byte(tt.t)); got != tt.want { - t.Errorf("%d. %q, %q = %v; want %v", i, tt.s, tt.t, got, tt.want) - } - truth := strings.EqualFold(tt.s, tt.t) - if truth != tt.want { - t.Errorf("strings.EqualFold doesn't agree with case %d", i) - } - } -} - -func TestFoldAgainstUnicode(t *testing.T) { - const bufSize = 5 - buf1 := make([]byte, 0, bufSize) - buf2 := make([]byte, 0, bufSize) - var runes []rune - for i := 0x20; i <= 0x7f; i++ { - runes = append(runes, rune(i)) - } - runes = append(runes, kelvin, smallLongEss) - - funcs := []struct { - name string - fold func(s, t []byte) bool - letter bool // must be ASCII letter - simple bool // must be simple ASCII letter (not 'S' or 'K') - }{ - { - name: "equalFoldRight", - fold: equalFoldRight, - }, - { - name: "asciiEqualFold", - fold: asciiEqualFold, - simple: true, - }, - { - name: "simpleLetterEqualFold", - fold: simpleLetterEqualFold, - simple: true, - letter: true, - }, - } - - for _, ff := range funcs { - for _, r := range runes { - if r >= utf8.RuneSelf { - continue - } - if ff.letter && !isASCIILetter(byte(r)) { - continue - } - if ff.simple && (r == 's' || r == 'S' || r == 'k' || r == 'K') { - continue - } - for _, r2 := range runes { - buf1 := append(buf1[:0], 'x') - buf2 := append(buf2[:0], 'x') - buf1 = buf1[:1+utf8.EncodeRune(buf1[1:bufSize], r)] - buf2 = buf2[:1+utf8.EncodeRune(buf2[1:bufSize], r2)] - buf1 = append(buf1, 'x') - buf2 = append(buf2, 'x') - want := bytes.EqualFold(buf1, buf2) - if got := ff.fold(buf1, buf2); got != want { - t.Errorf("%s(%q, %q) = %v; want %v", ff.name, buf1, buf2, got, want) - } - } - } - } -} - -func isASCIILetter(b byte) bool { - return ('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') -} diff --git a/vendor/cloud.google.com/go/internal/kokoro/build.sh b/vendor/cloud.google.com/go/internal/kokoro/build.sh deleted file mode 100755 index 0d20d3199..000000000 --- a/vendor/cloud.google.com/go/internal/kokoro/build.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# Fail on any error -set -eo pipefail - -# Display commands being run -set -x - -# cd to project dir on Kokoro instance -cd git/gocloud - -go version - -# Set $GOPATH -export GOPATH="$HOME/go" -GOCLOUD_HOME=$GOPATH/src/cloud.google.com/go -mkdir -p $GOCLOUD_HOME - -# Move code into $GOPATH and get dependencies -cp -R ./* $GOCLOUD_HOME -cd $GOCLOUD_HOME -go get -v ./... - -# # Don't run integration tests until we can protect against code from -# # untrusted forks reading and storing our service account key. -# cd internal/kokoro -# # Don't print out encryption keys, etc -# set +x -# key=$(cat $KOKORO_ARTIFACTS_DIR/keystore/*_encrypted_ba2d6f7723ed_key) -# iv=$(cat $KOKORO_ARTIFACTS_DIR/keystore/*_encrypted_ba2d6f7723ed_iv) -# pass=$(cat $KOKORO_ARTIFACTS_DIR/keystore/*_encrypted_ba2d6f7723ed_pass) - -# openssl aes-256-cbc -K $key -iv $iv -pass pass:$pass -in kokoro-key.json.enc -out key.json -d -# set -x - -# export GCLOUD_TESTS_GOLANG_KEY="$(pwd)/key.json" -# export GCLOUD_TESTS_GOLANG_PROJECT_ID="dulcet-port-762" -# cd $GOCLOUD_HOME - -# Run tests and tee output to log file, to be pushed to GCS as artifact. -go test -race -v -short ./... 2>&1 | tee $KOKORO_ARTIFACTS_DIR/$KOKORO_GERRIT_REVISION.log - -# Make sure README.md is up to date. -make -C internal/readme test diff diff --git a/vendor/cloud.google.com/go/internal/kokoro/kokoro-key.json.enc b/vendor/cloud.google.com/go/internal/kokoro/kokoro-key.json.enc Binary files differdeleted file mode 100644 index b23885469..000000000 --- a/vendor/cloud.google.com/go/internal/kokoro/kokoro-key.json.enc +++ /dev/null diff --git a/vendor/cloud.google.com/go/internal/optional/optional_test.go b/vendor/cloud.google.com/go/internal/optional/optional_test.go deleted file mode 100644 index 6fe6d6e8a..000000000 --- a/vendor/cloud.google.com/go/internal/optional/optional_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 optional - -import "testing" - -func TestConvertSuccess(t *testing.T) { - if got, want := ToBool(false), false; got != want { - t.Errorf("got %v, want %v", got, want) - } - if got, want := ToString(""), ""; got != want { - t.Errorf("got %v, want %v", got, want) - } - if got, want := ToInt(0), 0; got != want { - t.Errorf("got %v, want %v", got, want) - } - if got, want := ToUint(uint(0)), uint(0); got != want { - t.Errorf("got %v, want %v", got, want) - } - if got, want := ToFloat64(0.0), 0.0; got != want { - t.Errorf("got %v, want %v", got, want) - } -} - -func TestConvertFailure(t *testing.T) { - for _, f := range []func(){ - func() { ToBool(nil) }, - func() { ToBool(3) }, - func() { ToString(nil) }, - func() { ToString(3) }, - func() { ToInt(nil) }, - func() { ToInt("") }, - func() { ToUint(nil) }, - func() { ToUint("") }, - func() { ToFloat64(nil) }, - func() { ToFloat64("") }, - } { - if !panics(f) { - t.Error("got no panic, want panic") - } - } -} - -func panics(f func()) (b bool) { - defer func() { - if recover() != nil { - b = true - } - }() - f() - return false -} diff --git a/vendor/cloud.google.com/go/internal/pretty/diff.go b/vendor/cloud.google.com/go/internal/pretty/diff.go deleted file mode 100644 index 38a7cf1c5..000000000 --- a/vendor/cloud.google.com/go/internal/pretty/diff.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pretty - -import ( - "fmt" - "io/ioutil" - "os" - "os/exec" - "syscall" -) - -// Diff compares the pretty-printed representation of two values. The second -// return value reports whether the two values' representations are identical. -// If it is false, the first return value contains the diffs. -// -// The output labels the first value "want" and the second "got". -// -// Diff works by invoking the "diff" command. It will only succeed in -// environments where "diff" is on the shell path. -func Diff(want, got interface{}) (string, bool, error) { - fname1, err := writeToTemp(want) - if err != nil { - return "", false, err - } - defer os.Remove(fname1) - - fname2, err := writeToTemp(got) - if err != nil { - return "", false, err - } - defer os.Remove(fname2) - - cmd := exec.Command("diff", "-u", "--label=want", "--label=got", fname1, fname2) - out, err := cmd.Output() - if err == nil { - return string(out), true, nil - } - eerr, ok := err.(*exec.ExitError) - if !ok { - return "", false, err - } - ws, ok := eerr.Sys().(syscall.WaitStatus) - if !ok { - return "", false, err - } - if ws.ExitStatus() != 1 { - return "", false, err - } - // Exit status of 1 means no error, but diffs were found. - return string(out), false, nil -} - -func writeToTemp(v interface{}) (string, error) { - f, err := ioutil.TempFile("", "prettyDiff") - if err != nil { - return "", err - } - if _, err := fmt.Fprintf(f, "%+v\n", Value(v)); err != nil { - return "", err - } - if err := f.Close(); err != nil { - return "", err - } - return f.Name(), nil -} diff --git a/vendor/cloud.google.com/go/internal/pretty/diff_test.go b/vendor/cloud.google.com/go/internal/pretty/diff_test.go deleted file mode 100644 index 739cc50a8..000000000 --- a/vendor/cloud.google.com/go/internal/pretty/diff_test.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pretty - -import "testing" - -func TestDiff(t *testing.T) { - for _, test := range []struct { - v1, v2 interface{} - ok bool - want string - }{ - {5, 5, true, ""}, - {"foo", "foo", true, ""}, - {[]int{1, 2, 3}, []int{1, 0, 3}, false, `--- want -+++ got -@@ -1,5 +1,5 @@ - []int{ - 1, -- 2, -+ 0, - 3, - } -`}, - } { - got, ok, err := Diff(test.v1, test.v2) - if err != nil { - t.Errorf("%v vs. %v: %v", test.v1, test.v2, err) - continue - } - if ok != test.ok { - t.Errorf("%v vs. %v: got %t, want %t", test.v1, test.v2, ok, test.ok) - } - if got != test.want { - t.Errorf("%v vs. %v: got:\n%q\nwant:\n%q", test.v1, test.v2, got, test.want) - } - } -} diff --git a/vendor/cloud.google.com/go/internal/pretty/pretty.go b/vendor/cloud.google.com/go/internal/pretty/pretty.go deleted file mode 100644 index e5866aa03..000000000 --- a/vendor/cloud.google.com/go/internal/pretty/pretty.go +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pretty implements a simple pretty-printer. It is intended for -// debugging the output of tests. -// -// It follows pointers and produces multi-line output for complex values like -// slices, maps and structs. -package pretty - -import ( - "fmt" - "io" - "reflect" - "sort" - "strings" - "time" -) - -// Indent is the string output at each level of indentation. -var Indent = " " - -// Value returns a value that will print prettily when used as an -// argument for the %v or %s format specifiers. -// With no flags, struct fields and map keys with default values are omitted. -// With the '+' or '#' flags, all values are displayed. -// -// This package does not detect cycles. Attempting to print a Value that -// contains cycles will result in unbounded recursion. -func Value(v interface{}) val { return val{v: v} } - -type val struct{ v interface{} } - -// Format implements the fmt.Formatter interface. -func (v val) Format(s fmt.State, c rune) { - if c == 'v' || c == 's' { - fprint(s, reflect.ValueOf(v.v), state{ - defaults: s.Flag('+') || s.Flag('#'), - }) - } else { - fmt.Fprintf(s, "%%!%c(pretty.Val)", c) - } -} - -type state struct { - level int - prefix, suffix string - defaults bool -} - -const maxLevel = 100 - -var typeOfTime = reflect.TypeOf(time.Time{}) - -func fprint(w io.Writer, v reflect.Value, s state) { - if s.level > maxLevel { - fmt.Fprintln(w, "pretty: max nested depth exceeded") - return - } - indent := strings.Repeat(Indent, s.level) - fmt.Fprintf(w, "%s%s", indent, s.prefix) - if isNil(v) { - fmt.Fprintf(w, "nil%s", s.suffix) - return - } - if v.Type().Kind() == reflect.Interface { - v = v.Elem() - } - if v.Type() == typeOfTime { - fmt.Fprintf(w, "%s%s", v.Interface(), s.suffix) - return - } - for v.Type().Kind() == reflect.Ptr { - fmt.Fprintf(w, "&") - v = v.Elem() - } - switch v.Type().Kind() { - default: - fmt.Fprintf(w, "%s%s", short(v), s.suffix) - - case reflect.Array: - fmt.Fprintf(w, "%s{\n", v.Type()) - for i := 0; i < v.Len(); i++ { - fprint(w, v.Index(i), state{ - level: s.level + 1, - prefix: "", - suffix: ",", - defaults: s.defaults, - }) - fmt.Fprintln(w) - } - fmt.Fprintf(w, "%s}", indent) - - case reflect.Slice: - fmt.Fprintf(w, "%s{", v.Type()) - if v.Len() > 0 { - fmt.Fprintln(w) - for i := 0; i < v.Len(); i++ { - fprint(w, v.Index(i), state{ - level: s.level + 1, - prefix: "", - suffix: ",", - defaults: s.defaults, - }) - fmt.Fprintln(w) - } - } - fmt.Fprintf(w, "%s}%s", indent, s.suffix) - - case reflect.Map: - fmt.Fprintf(w, "%s{", v.Type()) - if v.Len() > 0 { - fmt.Fprintln(w) - keys := v.MapKeys() - maybeSort(keys, v.Type().Key()) - for _, key := range keys { - val := v.MapIndex(key) - if s.defaults || !isDefault(val) { - fprint(w, val, state{ - level: s.level + 1, - prefix: short(key) + ": ", - suffix: ",", - defaults: s.defaults, - }) - fmt.Fprintln(w) - } - } - } - fmt.Fprintf(w, "%s}%s", indent, s.suffix) - - case reflect.Struct: - t := v.Type() - fmt.Fprintf(w, "%s{\n", t) - for i := 0; i < t.NumField(); i++ { - f := v.Field(i) - if s.defaults || !isDefault(f) { - fprint(w, f, state{ - level: s.level + 1, - prefix: t.Field(i).Name + ": ", - suffix: ",", - defaults: s.defaults, - }) - fmt.Fprintln(w) - } - } - fmt.Fprintf(w, "%s}%s", indent, s.suffix) - } -} - -func isNil(v reflect.Value) bool { - if !v.IsValid() { - return true - } - switch v.Type().Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - return v.IsNil() - default: - return false - } -} - -func isDefault(v reflect.Value) bool { - if !v.IsValid() { - return true - } - t := v.Type() - switch t.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - return v.IsNil() - default: - if !v.CanInterface() { - return false - } - return t.Comparable() && v.Interface() == reflect.Zero(t).Interface() - } -} - -// short returns a short, one-line string for v. -func short(v reflect.Value) string { - if !v.IsValid() { - return "nil" - } - if v.Type().Kind() == reflect.String { - return fmt.Sprintf("%q", v) - } - return fmt.Sprintf("%v", v) -} - -func indent(w io.Writer, level int) { - for i := 0; i < level; i++ { - io.WriteString(w, Indent) // ignore errors - } -} - -func maybeSort(vs []reflect.Value, t reflect.Type) { - if less := lessFunc(t); less != nil { - sort.Sort(&sorter{vs, less}) - } -} - -// lessFunc returns a function that implements the "<" operator -// for the given type, or nil if the type doesn't support "<" . -func lessFunc(t reflect.Type) func(v1, v2 interface{}) bool { - switch t.Kind() { - case reflect.String: - return func(v1, v2 interface{}) bool { return v1.(string) < v2.(string) } - case reflect.Int: - return func(v1, v2 interface{}) bool { return v1.(int) < v2.(int) } - case reflect.Int8: - return func(v1, v2 interface{}) bool { return v1.(int8) < v2.(int8) } - case reflect.Int16: - return func(v1, v2 interface{}) bool { return v1.(int16) < v2.(int16) } - case reflect.Int32: - return func(v1, v2 interface{}) bool { return v1.(int32) < v2.(int32) } - case reflect.Int64: - return func(v1, v2 interface{}) bool { return v1.(int64) < v2.(int64) } - case reflect.Uint: - return func(v1, v2 interface{}) bool { return v1.(uint) < v2.(uint) } - case reflect.Uint8: - return func(v1, v2 interface{}) bool { return v1.(uint8) < v2.(uint8) } - case reflect.Uint16: - return func(v1, v2 interface{}) bool { return v1.(uint16) < v2.(uint16) } - case reflect.Uint32: - return func(v1, v2 interface{}) bool { return v1.(uint32) < v2.(uint32) } - case reflect.Uint64: - return func(v1, v2 interface{}) bool { return v1.(uint64) < v2.(uint64) } - case reflect.Float32: - return func(v1, v2 interface{}) bool { return v1.(float32) < v2.(float32) } - case reflect.Float64: - return func(v1, v2 interface{}) bool { return v1.(float64) < v2.(float64) } - default: - return nil - } -} - -type sorter struct { - vs []reflect.Value - less func(v1, v2 interface{}) bool -} - -func (s *sorter) Len() int { return len(s.vs) } -func (s *sorter) Swap(i, j int) { s.vs[i], s.vs[j] = s.vs[j], s.vs[i] } -func (s *sorter) Less(i, j int) bool { return s.less(s.vs[i].Interface(), s.vs[j].Interface()) } diff --git a/vendor/cloud.google.com/go/internal/pretty/pretty_test.go b/vendor/cloud.google.com/go/internal/pretty/pretty_test.go deleted file mode 100644 index 6e2ff8b7d..000000000 --- a/vendor/cloud.google.com/go/internal/pretty/pretty_test.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pretty - -import ( - "fmt" - "strings" - "testing" -) - -type S struct { - X int - Y bool - z *string -} - -func TestSprint(t *testing.T) { - Indent = "~" - i := 17 - - for _, test := range []struct { - value interface{} - want string - }{ - // primitives and pointer - {nil, "nil"}, - {3, "3"}, - {9.8, "9.8"}, - {true, "true"}, - {"foo", `"foo"`}, - {&i, "&17"}, - // array and slice - {[3]int{1, 2, 3}, "[3]int{\n~1,\n~2,\n~3,\n}"}, - {[]int{1, 2, 3}, "[]int{\n~1,\n~2,\n~3,\n}"}, - {[]int{}, "[]int{}"}, - {[]string{"foo"}, "[]string{\n~\"foo\",\n}"}, - // map - {map[int]bool{}, "map[int]bool{}"}, - {map[int]bool{1: true, 2: false, 3: true}, - "map[int]bool{\n~1: true,\n~3: true,\n}"}, - // struct - {S{}, "pretty.S{\n}"}, - {S{3, true, ptr("foo")}, - "pretty.S{\n~X: 3,\n~Y: true,\n~z: &\"foo\",\n}"}, - // interface - {[]interface{}{&i}, "[]interface {}{\n~&17,\n}"}, - // nesting - {[]S{{1, false, ptr("a")}, {2, true, ptr("b")}}, - `[]pretty.S{ -~pretty.S{ -~~X: 1, -~~z: &"a", -~}, -~pretty.S{ -~~X: 2, -~~Y: true, -~~z: &"b", -~}, -}`}, - } { - got := fmt.Sprintf("%v", Value(test.value)) - if got != test.want { - t.Errorf("%v: got:\n%q\nwant:\n%q", test.value, got, test.want) - } - } -} - -func TestWithDefaults(t *testing.T) { - Indent = "~" - for _, test := range []struct { - value interface{} - want string - }{ - {map[int]bool{1: true, 2: false, 3: true}, - "map[int]bool{\n~1: true,\n~2: false,\n~3: true,\n}"}, - {S{}, "pretty.S{\n~X: 0,\n~Y: false,\n~z: nil,\n}"}, - } { - got := fmt.Sprintf("%+v", Value(test.value)) - if got != test.want { - t.Errorf("%v: got:\n%q\nwant:\n%q", test.value, got, test.want) - } - } -} - -func TestBadVerb(t *testing.T) { - got := fmt.Sprintf("%d", Value(8)) - want := "%!d(" - if !strings.HasPrefix(got, want) { - t.Errorf("got %q, want prefix %q", got, want) - } -} - -func ptr(s string) *string { return &s } diff --git a/vendor/cloud.google.com/go/internal/readme/Makefile b/vendor/cloud.google.com/go/internal/readme/Makefile deleted file mode 100644 index 1c1f4e1d3..000000000 --- a/vendor/cloud.google.com/go/internal/readme/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# Rebuild the README.md file at repo root by inserting code samples -# from compilable go files. - -SHELL=/bin/bash - -GOCLOUD_HOME=$(GOPATH)/src/cloud.google.com/go -README=$(GOCLOUD_HOME)/README.md - -.PHONY: readme test test-good test-bad-go test-bad-md - -readme: - @tmp=$$(mktemp); \ - awk -f snipmd.awk snippets.go $(README) > $$tmp; \ - mv $$tmp $(README) - -diff: - diff $(README) <(awk -f snipmd.awk snippets.go $(README)) - -test: test-good test-bad-go test-bad-md - @echo PASS - -test-good: - @echo testdata/good.md - @cd testdata >& /dev/null; \ - diff -u want.md <(awk -f ../snipmd.awk snips.go good.md) - @echo "testdata/want.md (round trip)" - @cd testdata >& /dev/null; \ - diff -u want.md <(awk -f ../snipmd.awk snips.go want.md) - -test-bad-go: - @for f in testdata/bad-*.go; do \ - echo $$f; \ - if awk -f snipmd.awk $$f >& /dev/null; then \ - echo "$f succeeded, want failure"; \ - exit 1; \ - fi; \ - done - -test-bad-md: - @for f in testdata/bad-*.md; do \ - echo $$f; \ - if awk -f snipmd.awk testdata/snips.go $$f >& /dev/null; then \ - echo "$f succeeded, want failure"; \ - exit 1; \ - fi; \ - done - - diff --git a/vendor/cloud.google.com/go/internal/readme/snipmd.awk b/vendor/cloud.google.com/go/internal/readme/snipmd.awk deleted file mode 100644 index 3a523832a..000000000 --- a/vendor/cloud.google.com/go/internal/readme/snipmd.awk +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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. - -# snipmd inserts code snippets from Go source files into a markdown file. -# -# Call with one or more .go files and a .md file: -# -# awk -f snipmd.awk foo.go bar.go template.md -# -# In the Go files, start a snippet with -# //[ NAME -# and end it with -# //] -# -# In the markdown, write -# [snip]:# NAME -# to insert the snippet NAME just below that line. -# If there is already a code block after the [snip]:# line, it will be -# replaced, so a previous output can be used as input. -# -# The following transformations are made to the Go code: -# - The first tab of each line is removed. -# - Trailing blank lines are removed. -# - `ELLIPSIS` and `_ = ELLIPSIS` are replaced by `...` - - -/^[ \t]*\/\/\[/ { # start snippet in Go file - if (inGo()) { - if ($2 == "") { - die("missing snippet name") - } - curSnip = $2 - next - } -} - -/^[ \t]*\/\/]/ { # end snippet in Go file - if (inGo()) { - if (curSnip != "") { - # Remove all but one trailing newline. - gsub(/\n+$/, "\n", snips[curSnip]) - curSnip = "" - next - } else { - die("//] without corresponding //[") - } - } -} - -ENDFILE { - if (curSnip != "") { - die("unclosed snippet: " curSnip) - } -} - -# Skip code blocks in the input that immediately follow [snip]:# lines, -# because we just inserted the snippet. Supports round-tripping. -/^```go$/,/^```$/ { - if (inMarkdown() && afterSnip) { - next - } -} - -# Matches every line. -{ - if (curSnip != "") { - line = $0 - # Remove initial tab, if any. - if (line ~ /^\t/) { - line = substr(line, 2) - } - # Replace ELLIPSIS. - gsub(/_ = ELLIPSIS/, "...", line) - gsub(/ELLIPSIS/, "...", line) - - snips[curSnip] = snips[curSnip] line "\n" - } else if (inMarkdown()) { - afterSnip = 0 - # Copy .md to output. - print - } -} - -$1 ~ /\[snip\]:#/ { # Snippet marker in .md file. - if (inMarkdown()) { - # We expect '[snip]:#' to be followed by '(NAME)' - if ($2 !~ /\(.*\)/) { - die("bad snip spec: " $0) - } - name = substr($2, 2, length($2)-2) - if (snips[name] == "") { - die("no snippet named " name) - } - printf("```go\n%s```\n", snips[name]) - afterSnip = 1 - } -} - - -function inMarkdown() { - return match(FILENAME, /\.md$/) -} - -function inGo() { - return match(FILENAME, /\.go$/) -} - - -function die(msg) { - printf("%s:%d: %s\n", FILENAME, FNR, msg) > "/dev/stderr" - exit 1 -} diff --git a/vendor/cloud.google.com/go/internal/readme/snippets.go b/vendor/cloud.google.com/go/internal/readme/snippets.go deleted file mode 100644 index 049710d99..000000000 --- a/vendor/cloud.google.com/go/internal/readme/snippets.go +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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. - -// This file holds samples that are embedded into README.md. - -// This file has to compile, but need not execute. -// If it fails to compile, fix it, then run `make` to regenerate README.md. - -package readme - -import ( - "fmt" - "io/ioutil" - "log" - "time" - - "cloud.google.com/go/bigquery" - "cloud.google.com/go/datastore" - "cloud.google.com/go/logging" - "cloud.google.com/go/pubsub" - "cloud.google.com/go/spanner" - "cloud.google.com/go/storage" - - "golang.org/x/net/context" - "golang.org/x/oauth2" - "google.golang.org/api/iterator" - "google.golang.org/api/option" -) - -var ctx context.Context - -const END = 0 - -func auth() { - //[ auth - client, err := storage.NewClient(ctx) - //] - _ = client - _ = err -} - -func auth2() { - //[ auth-JSON - client, err := storage.NewClient(ctx, option.WithServiceAccountFile("path/to/keyfile.json")) - //] - _ = client - _ = err -} - -func auth3() { - var ELLIPSIS oauth2.TokenSource - //[ auth-ts - tokenSource := ELLIPSIS - client, err := storage.NewClient(ctx, option.WithTokenSource(tokenSource)) - //] - _ = client - _ = err -} - -func datastoreSnippets() { - //[ datastore-1 - client, err := datastore.NewClient(ctx, "my-project-id") - if err != nil { - log.Fatal(err) - } - //] - - //[ datastore-2 - type Post struct { - Title string - Body string `datastore:",noindex"` - PublishedAt time.Time - } - keys := []*datastore.Key{ - datastore.NameKey("Post", "post1", nil), - datastore.NameKey("Post", "post2", nil), - } - posts := []*Post{ - {Title: "Post 1", Body: "...", PublishedAt: time.Now()}, - {Title: "Post 2", Body: "...", PublishedAt: time.Now()}, - } - if _, err := client.PutMulti(ctx, keys, posts); err != nil { - log.Fatal(err) - } - //] -} - -func storageSnippets() { - //[ storage-1 - client, err := storage.NewClient(ctx) - if err != nil { - log.Fatal(err) - } - //] - - //[ storage-2 - // Read the object1 from bucket. - rc, err := client.Bucket("bucket").Object("object1").NewReader(ctx) - if err != nil { - log.Fatal(err) - } - defer rc.Close() - body, err := ioutil.ReadAll(rc) - if err != nil { - log.Fatal(err) - } - //] - _ = body -} - -func pubsubSnippets() { - //[ pubsub-1 - client, err := pubsub.NewClient(ctx, "project-id") - if err != nil { - log.Fatal(err) - } - //] - - const ELLIPSIS = 0 - - //[ pubsub-2 - // Publish "hello world" on topic1. - topic := client.Topic("topic1") - res := topic.Publish(ctx, &pubsub.Message{ - Data: []byte("hello world"), - }) - // The publish happens asynchronously. - // Later, you can get the result from res: - _ = ELLIPSIS - msgID, err := res.Get(ctx) - if err != nil { - log.Fatal(err) - } - - // Use a callback to receive messages via subscription1. - sub := client.Subscription("subscription1") - err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) { - fmt.Println(m.Data) - m.Ack() // Acknowledge that we've consumed the message. - }) - if err != nil { - log.Println(err) - } - //] - _ = msgID -} - -func bqSnippets() { - //[ bq-1 - c, err := bigquery.NewClient(ctx, "my-project-ID") - if err != nil { - // TODO: Handle error. - } - //] - - //[ bq-2 - // Construct a query. - q := c.Query(` - SELECT year, SUM(number) - FROM [bigquery-public-data:usa_names.usa_1910_2013] - WHERE name = "William" - GROUP BY year - ORDER BY year -`) - // Execute the query. - it, err := q.Read(ctx) - if err != nil { - // TODO: Handle error. - } - // Iterate through the results. - for { - var values []bigquery.Value - err := it.Next(&values) - if err == iterator.Done { - break - } - if err != nil { - // TODO: Handle error. - } - fmt.Println(values) - } - //] -} - -func loggingSnippets() { - //[ logging-1 - ctx := context.Background() - client, err := logging.NewClient(ctx, "my-project") - if err != nil { - // TODO: Handle error. - } - //] - //[ logging-2 - logger := client.Logger("my-log") - logger.Log(logging.Entry{Payload: "something happened!"}) - //] - - //[ logging-3 - err = client.Close() - if err != nil { - // TODO: Handle error. - } - //] -} - -func spannerSnippets() { - //[ spanner-1 - client, err := spanner.NewClient(ctx, "projects/P/instances/I/databases/D") - if err != nil { - log.Fatal(err) - } - //] - - //[ spanner-2 - // Simple Reads And Writes - _, err = client.Apply(ctx, []*spanner.Mutation{ - spanner.Insert("Users", - []string{"name", "email"}, - []interface{}{"alice", "a@example.com"})}) - if err != nil { - log.Fatal(err) - } - row, err := client.Single().ReadRow(ctx, "Users", - spanner.Key{"alice"}, []string{"email"}) - if err != nil { - log.Fatal(err) - } - //] - _ = row -} diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-name.go b/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-name.go deleted file mode 100644 index 5b96a50be..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-name.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 readme - -import "fmt" - -func f() { - //[ - fmt.Println() - //] -} diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-open.go b/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-open.go deleted file mode 100644 index d69fbcb49..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/bad-no-open.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 readme - -func f() { - //] -} diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/bad-nosnip.md b/vendor/cloud.google.com/go/internal/readme/testdata/bad-nosnip.md deleted file mode 100644 index e3a1a3c5c..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/bad-nosnip.md +++ /dev/null @@ -1,2 +0,0 @@ -[snip]:# (unknown) - diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/bad-spec.md b/vendor/cloud.google.com/go/internal/readme/testdata/bad-spec.md deleted file mode 100644 index 2f46ad853..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/bad-spec.md +++ /dev/null @@ -1 +0,0 @@ -[snip]:# missing-parens diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/bad-unclosed.go b/vendor/cloud.google.com/go/internal/readme/testdata/bad-unclosed.go deleted file mode 100644 index 486ce42f7..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/bad-unclosed.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 readme - -// unclosed snippet - -func f() { - //[ X -} diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/good.md b/vendor/cloud.google.com/go/internal/readme/testdata/good.md deleted file mode 100644 index c300afea8..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/good.md +++ /dev/null @@ -1,18 +0,0 @@ -This template is for testing snipmd.awk. - -Put the first snippet here. - -[snip]:# (first) - -And now the second. -[snip]:# (second) - -A top-level snippet. - -[snip]:# (top-level) - -```go -// A code block that is not included. -``` - -And we're done. diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/snips.go b/vendor/cloud.google.com/go/internal/readme/testdata/snips.go deleted file mode 100644 index cddb5f9d5..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/snips.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 readme - -import ( - "errors" - "fmt" -) - -func f() { - ELLIPSIS := 3 - //[ first - fmt.Println("hello") - x := ELLIPSIS - //] - - //[ second - if x > 2 { - _ = ELLIPSIS - } - //] -} - -//[ top-level -var ErrBad = errors.New("bad") - -//] diff --git a/vendor/cloud.google.com/go/internal/readme/testdata/want.md b/vendor/cloud.google.com/go/internal/readme/testdata/want.md deleted file mode 100644 index 176bd061a..000000000 --- a/vendor/cloud.google.com/go/internal/readme/testdata/want.md +++ /dev/null @@ -1,30 +0,0 @@ -This template is for testing snipmd.awk. - -Put the first snippet here. - -[snip]:# (first) -```go -fmt.Println("hello") -x := ... -``` - -And now the second. -[snip]:# (second) -```go -if x > 2 { - ... -} -``` - -A top-level snippet. - -[snip]:# (top-level) -```go -var ErrBad = errors.New("bad") -``` - -```go -// A code block that is not included. -``` - -And we're done. diff --git a/vendor/cloud.google.com/go/internal/retry_test.go b/vendor/cloud.google.com/go/internal/retry_test.go deleted file mode 100644 index 590b55508..000000000 --- a/vendor/cloud.google.com/go/internal/retry_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 internal - -import ( - "errors" - "testing" - "time" - - "golang.org/x/net/context" - - gax "github.com/googleapis/gax-go" -) - -func TestRetry(t *testing.T) { - ctx := context.Background() - // Without a context deadline, retry will run until the function - // says not to retry any more. - n := 0 - endRetry := errors.New("end retry") - err := retry(ctx, gax.Backoff{}, - func() (bool, error) { - n++ - if n < 10 { - return false, nil - } - return true, endRetry - }, - func(context.Context, time.Duration) error { return nil }) - if got, want := err, endRetry; got != want { - t.Errorf("got %v, want %v", err, endRetry) - } - if n != 10 { - t.Errorf("n: got %d, want %d", n, 10) - } - - // If the context has a deadline, sleep will return an error - // and end the function. - n = 0 - err = retry(ctx, gax.Backoff{}, - func() (bool, error) { return false, nil }, - func(context.Context, time.Duration) error { - n++ - if n < 10 { - return nil - } - return context.DeadlineExceeded - }) - if err == nil { - t.Error("got nil, want error") - } -} diff --git a/vendor/cloud.google.com/go/internal/testutil/context.go b/vendor/cloud.google.com/go/internal/testutil/context.go deleted file mode 100644 index cdb440ee3..000000000 --- a/vendor/cloud.google.com/go/internal/testutil/context.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// 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 testutil contains helper functions for writing tests. -package testutil - -import ( - "io/ioutil" - "log" - "os" - - "golang.org/x/net/context" - "golang.org/x/oauth2" - "golang.org/x/oauth2/google" -) - -const ( - envProjID = "GCLOUD_TESTS_GOLANG_PROJECT_ID" - envPrivateKey = "GCLOUD_TESTS_GOLANG_KEY" -) - -// ProjID returns the project ID to use in integration tests, or the empty -// string if none is configured. -func ProjID() string { - projID := os.Getenv(envProjID) - if projID == "" { - return "" - } - return projID -} - -// TokenSource returns the OAuth2 token source to use in integration tests, -// or nil if none is configured. If the environment variable is unset, -// TokenSource will try to find 'Application Default Credentials'. Else, -// TokenSource will return nil. -// TokenSource will log.Fatal if the token source is specified but missing or invalid. -func TokenSource(ctx context.Context, scopes ...string) oauth2.TokenSource { - key := os.Getenv(envPrivateKey) - if key == "" { // Try for application default credentials. - ts, err := google.DefaultTokenSource(ctx, scopes...) - if err != nil { - log.Println("No 'Application Default Credentials' found.") - return nil - } - return ts - } - jsonKey, err := ioutil.ReadFile(key) - if err != nil { - log.Fatalf("Cannot read the JSON key file, err: %v", err) - } - conf, err := google.JWTConfigFromJSON(jsonKey, scopes...) - if err != nil { - log.Fatalf("google.JWTConfigFromJSON: %v", err) - } - return conf.TokenSource(ctx) -} diff --git a/vendor/cloud.google.com/go/internal/testutil/server.go b/vendor/cloud.google.com/go/internal/testutil/server.go deleted file mode 100644 index e6b7b9737..000000000 --- a/vendor/cloud.google.com/go/internal/testutil/server.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2016 Google Inc. All Rights Reserved. - -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 testutil - -import ( - "net" - - grpc "google.golang.org/grpc" -) - -// A Server is an in-process gRPC server, listening on a system-chosen port on -// the local loopback interface. Servers are for testing only and are not -// intended to be used in production code. -// -// To create a server, make a new Server, register your handlers, then call -// Start: -// -// srv, err := NewServer() -// ... -// mypb.RegisterMyServiceServer(srv.Gsrv, &myHandler) -// .... -// srv.Start() -// -// Clients should connect to the server with no security: -// -// conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure()) -// ... -type Server struct { - Addr string - l net.Listener - Gsrv *grpc.Server -} - -// NewServer creates a new Server. The Server will be listening for gRPC connections -// at the address named by the Addr field, without TLS. -func NewServer(opts ...grpc.ServerOption) (*Server, error) { - l, err := net.Listen("tcp", "127.0.0.1:0") - if err != nil { - return nil, err - } - s := &Server{ - Addr: l.Addr().String(), - l: l, - Gsrv: grpc.NewServer(opts...), - } - return s, nil -} - -// Start causes the server to start accepting incoming connections. -// Call Start after registering handlers. -func (s *Server) Start() { - go s.Gsrv.Serve(s.l) -} - -// Close shuts down the server. -func (s *Server) Close() { - s.Gsrv.Stop() - s.l.Close() -} diff --git a/vendor/cloud.google.com/go/internal/testutil/server_test.go b/vendor/cloud.google.com/go/internal/testutil/server_test.go deleted file mode 100644 index 817ce4ee7..000000000 --- a/vendor/cloud.google.com/go/internal/testutil/server_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 testutil - -import ( - "testing" - - grpc "google.golang.org/grpc" -) - -func TestNewServer(t *testing.T) { - srv, err := NewServer() - if err != nil { - t.Fatal(err) - } - srv.Start() - conn, err := grpc.Dial(srv.Addr, grpc.WithInsecure()) - if err != nil { - t.Fatal(err) - } - conn.Close() - srv.Close() -} diff --git a/vendor/cloud.google.com/go/internal/testutil/unique.go b/vendor/cloud.google.com/go/internal/testutil/unique.go deleted file mode 100644 index 84a377789..000000000 --- a/vendor/cloud.google.com/go/internal/testutil/unique.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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. - -// This file supports generating unique IDs so that multiple test executions -// don't interfere with each other, and cleaning up old entities that may -// remain if tests exit early. - -package testutil - -import ( - "fmt" - "regexp" - "strconv" - "sync" - "time" -) - -var startTime = time.Now().UTC() - -// A UIDSpace manages a set of unique IDs distinguished by a prefix. -type UIDSpace struct { - Prefix string - re *regexp.Regexp - mu sync.Mutex - count int -} - -func NewUIDSpace(prefix string) *UIDSpace { - return &UIDSpace{ - Prefix: prefix, - re: regexp.MustCompile("^" + regexp.QuoteMeta(prefix) + `-(\d{4})(\d{2})(\d{2})-(\d+)-\d+$`), - } - -} - -// New generates a new unique ID . The ID consists of the UIDSpace's prefix, a -// timestamp, and a counter value. All unique IDs generated in the same test -// execution will have the same timestamp. -// -// Aside from the characters in the prefix, IDs contain only letters, numbers -// and hyphens. -func (s *UIDSpace) New() string { return s.newID(startTime) } - -func (s *UIDSpace) newID(t time.Time) string { - s.mu.Lock() - c := s.count - s.count++ - s.mu.Unlock() - // Write the time as a date followed by nanoseconds from midnight of that date. - // That makes it easier to see the approximate time of the ID when it is displayed. - y, m, d := t.Date() - ns := t.Sub(time.Date(y, m, d, 0, 0, 0, 0, time.UTC)) - // Zero-pad the counter for lexical sort order for IDs with the same timestamp. - return fmt.Sprintf("%s-%04d%02d%02d-%d-%04d", s.Prefix, y, m, d, ns, c) -} - -// Timestamp extracts the timestamp of uid, which must have been generated by -// s. The second return value is true on success, false if there was a problem. -func (s *UIDSpace) Timestamp(uid string) (time.Time, bool) { - subs := s.re.FindStringSubmatch(uid) - if subs == nil { - return time.Time{}, false - } - y, err1 := strconv.Atoi(subs[1]) - m, err2 := strconv.Atoi(subs[2]) - d, err3 := strconv.Atoi(subs[3]) - ns, err4 := strconv.Atoi(subs[4]) - if err1 != nil || err2 != nil || err3 != nil || err4 != nil { - return time.Time{}, false - } - return time.Date(y, time.Month(m), d, 0, 0, 0, ns, time.UTC), true -} - -// Older reports whether uid was created by m and has a timestamp older than -// the current time by at least d. -func (s *UIDSpace) Older(uid string, d time.Duration) bool { - ts, ok := s.Timestamp(uid) - if !ok { - return false - } - return time.Since(ts) > d -} diff --git a/vendor/cloud.google.com/go/internal/testutil/unique_test.go b/vendor/cloud.google.com/go/internal/testutil/unique_test.go deleted file mode 100644 index c312e8fbe..000000000 --- a/vendor/cloud.google.com/go/internal/testutil/unique_test.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 testutil - -import ( - "testing" - "time" -) - -func TestNew(t *testing.T) { - s := NewUIDSpace("prefix") - tm := time.Date(2017, 1, 6, 0, 0, 0, 21, time.UTC) - got := s.newID(tm) - want := "prefix-20170106-21-0000" - if got != want { - t.Errorf("got %q, want %q", got, want) - } -} - -func TestTimestamp(t *testing.T) { - s := NewUIDSpace("unique-ID") - uid := s.New() - got, ok := s.Timestamp(uid) - if !ok { - t.Fatal("got ok = false, want true") - } - if !startTime.Equal(got) { - t.Errorf("got %s, want %s", got, startTime) - } - - got, ok = s.Timestamp("unique-ID-20160308-123-8") - if !ok { - t.Fatal("got false, want true") - } - if want := time.Date(2016, 3, 8, 0, 0, 0, 123, time.UTC); !want.Equal(got) { - t.Errorf("got %s, want %s", got, want) - } - if _, ok = s.Timestamp("invalid-time-1234"); ok { - t.Error("got true, want false") - } -} - -func TestOlder(t *testing.T) { - s := NewUIDSpace("uid") - // A non-matching ID returns false. - id2 := NewUIDSpace("different-prefix").New() - if got, want := s.Older(id2, time.Second), false; got != want { - t.Errorf("got %t, want %t", got, want) - } -} diff --git a/vendor/cloud.google.com/go/internal/tracecontext/tracecontext.go b/vendor/cloud.google.com/go/internal/tracecontext/tracecontext.go deleted file mode 100644 index 34d220279..000000000 --- a/vendor/cloud.google.com/go/internal/tracecontext/tracecontext.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 tracecontext provides encoders and decoders for Stackdriver Trace contexts. -package tracecontext - -import ( - "encoding/binary" -) - -const ( - versionID = 0 - traceIDField = 0 - spanIDField = 1 - optsField = 2 - - traceIDLen = 16 - spanIDLen = 8 - optsLen = 1 - - versionOffset = 0 - traceIDOffset = 1 - spanIDOffset = traceIDOffset + 1 + traceIDLen - optsOffset = spanIDOffset + 1 + spanIDLen - - totalLen = optsOffset + 1 + optsLen -) - -// Encode encodes trace ID, span ID and options into dst. The number of bytes -// written will be returned. If len(dst) isn't big enough to fit the trace context, -// a negative number is returned. -func Encode(dst []byte, traceID [2]uint64, spanID uint64, opts byte) (n int) { - if len(dst) < totalLen { - return -1 - } - var offset = 0 - putByte := func(b byte) { dst[offset] = b; offset++ } - putUint64 := func(u uint64) { binary.LittleEndian.PutUint64(dst[offset:], u); offset += 8 } - - putByte(versionID) - putByte(traceIDField) - putUint64(traceID[1]) - putUint64(traceID[0]) - putByte(spanIDField) - putUint64(spanID) - putByte(optsField) - putByte(opts) - - return offset -} - -// Decode decodes the src into a trace ID, span ID and options. If src doesn't -// contain a valid trace context, ok = false is returned. -func Decode(src []byte) (traceID [2]uint64, spanID uint64, opts byte, ok bool) { - if len(src) < totalLen { - return traceID, 0, 0, false - } - var offset = 0 - readByte := func() byte { b := src[offset]; offset++; return b } - readUint64 := func() uint64 { v := binary.LittleEndian.Uint64(src[offset:]); offset += 8; return v } - if readByte() != versionID { - return traceID, 0, 0, false - } - for offset < len(src) { - switch readByte() { - case traceIDField: - traceID[1] = readUint64() - traceID[0] = readUint64() - case spanIDField: - spanID = readUint64() - case optsField: - opts = readByte() - } - } - return traceID, spanID, opts, true -} diff --git a/vendor/cloud.google.com/go/internal/tracecontext/tracecontext_test.go b/vendor/cloud.google.com/go/internal/tracecontext/tracecontext_test.go deleted file mode 100644 index f2a3ad4c8..000000000 --- a/vendor/cloud.google.com/go/internal/tracecontext/tracecontext_test.go +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// 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 tracecontext - -import ( - "reflect" - "testing" -) - -var validData = []byte{0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100, 101, 102, 103, 104, 2, 1} - -func TestDecode(t *testing.T) { - tests := []struct { - name string - data []byte - wantTraceID [2]uint64 - wantSpanID uint64 - wantOpts byte - wantOk bool - }{ - { - name: "nil data", - data: nil, - wantTraceID: [2]uint64{}, - wantSpanID: 0, - wantOpts: 0, - wantOk: false, - }, - { - name: "short data", - data: []byte{0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77}, - wantTraceID: [2]uint64{}, - wantSpanID: 0, - wantOpts: 0, - wantOk: false, - }, - { - name: "wrong field number", - data: []byte{0, 1, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77}, - wantTraceID: [2]uint64{}, - wantSpanID: 0, - wantOpts: 0, - wantOk: false, - }, - { - name: "valid data", - data: validData, - wantTraceID: [2]uint64{0x4F4E4D4C4B4A4948, 0x4746454443424140}, - wantSpanID: 0x6867666564636261, - wantOpts: 1, - wantOk: true, - }, - } - for _, tt := range tests { - gotTraceID, gotSpanID, gotOpts, gotOk := Decode(tt.data) - if !reflect.DeepEqual(gotTraceID, tt.wantTraceID) { - t.Errorf("%s: Decode() gotTraceID = %v, want %v", tt.name, gotTraceID, tt.wantTraceID) - } - if gotSpanID != tt.wantSpanID { - t.Errorf("%s: Decode() gotSpanID = %v, want %v", tt.name, gotSpanID, tt.wantSpanID) - } - if gotOpts != tt.wantOpts { - t.Errorf("%s: Decode() gotOpts = %v, want %v", tt.name, gotOpts, tt.wantOpts) - } - if gotOk != tt.wantOk { - t.Errorf("%s: Decode() gotOk = %v, want %v", tt.name, gotOk, tt.wantOk) - } - } -} - -func TestEncode(t *testing.T) { - tests := []struct { - name string - dst []byte - traceID [2]uint64 - spanID uint64 - opts byte - wantN int - wantData []byte - }{ - { - name: "short data", - dst: make([]byte, 0), - traceID: [2]uint64{5714589967255750984, 5135868584551137600}, - spanID: 0x6867666564636261, - opts: 1, - wantN: -1, - wantData: make([]byte, 0), - }, - { - name: "valid data", - dst: make([]byte, totalLen), - traceID: [2]uint64{5714589967255750984, 5135868584551137600}, - spanID: 0x6867666564636261, - opts: 1, - wantN: totalLen, - wantData: validData, - }, - } - for _, tt := range tests { - gotN := Encode(tt.dst, tt.traceID, tt.spanID, tt.opts) - if gotN != tt.wantN { - t.Errorf("%s: n = %v, want %v", tt.name, gotN, tt.wantN) - } - if gotData := tt.dst; !reflect.DeepEqual(gotData, tt.wantData) { - t.Errorf("%s: dst = %v, want %v", tt.name, gotData, tt.wantData) - } - } -} - -func BenchmarkDecode(b *testing.B) { - for i := 0; i < b.N; i++ { - Decode(validData) - } -} - -func BenchmarkEncode(b *testing.B) { - for i := 0; i < b.N; i++ { - Encode(validData, [2]uint64{1, 1}, 1, 1) - } -} diff --git a/vendor/cloud.google.com/go/internal/version/version_test.go b/vendor/cloud.google.com/go/internal/version/version_test.go deleted file mode 100644 index 7e032f05b..000000000 --- a/vendor/cloud.google.com/go/internal/version/version_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 version - -import "testing" - -func TestGoVer(t *testing.T) { - for _, tst := range []struct { - in, want string - }{ - {"go1.8", "1.8.0"}, - {"go1.7.3", "1.7.3"}, - {"go1.8.typealias", "1.8.0-typealias"}, - {"go1.8beta1", "1.8.0-beta1"}, - {"go1.8rc2", "1.8.0-rc2"}, - {"devel +824f981dd4b7 Tue Apr 29 21:41:54 2014 -0400", "824f981dd4b7"}, - {"foo bar zipzap", ""}, - } { - if got := goVer(tst.in); got != tst.want { - t.Errorf("goVer(%q) = %q, want %q", tst.in, got, tst.want) - } - } -} |
