vendor cleanup: remove unused,non-go and test files

This commit is contained in:
Madhu Rajanna
2019-01-16 00:05:52 +05:30
parent 52cf4aa902
commit b10ba188e7
15421 changed files with 17 additions and 4208853 deletions

View File

@ -1,13 +0,0 @@
language: go
go:
- 1.4
- 1.3
- 1.2
- tip
install:
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
script:
- go test -cover

View File

@ -1,67 +0,0 @@
# How to contribute #
We'd love to accept your patches and contributions to this project. There are
a just a few small guidelines you need to follow.
## Contributor License Agreement ##
Contributions to any Google project must be accompanied by a Contributor
License Agreement. This is not a copyright **assignment**, it simply gives
Google permission to use and redistribute your contributions as part of the
project.
* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual
CLA][].
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA][].
You generally only need to submit a CLA once, so if you've already submitted
one (even if it was for a different project), you probably don't need to do it
again.
[individual CLA]: https://developers.google.com/open-source/cla/individual
[corporate CLA]: https://developers.google.com/open-source/cla/corporate
## Submitting a patch ##
1. It's generally best to start by opening a new issue describing the bug or
feature you're intending to fix. Even if you think it's relatively minor,
it's helpful to know what people are working on. Mention in the initial
issue that you are planning to work on that bug or feature so that it can
be assigned to you.
1. Follow the normal process of [forking][] the project, and setup a new
branch to work in. It's important that each group of changes be done in
separate branches in order to ensure that a pull request only includes the
commits related to that bug or feature.
1. Go makes it very simple to ensure properly formatted code, so always run
`go fmt` on your code before committing it. You should also run
[golint][] over your code. As noted in the [golint readme][], it's not
strictly necessary that your code be completely "lint-free", but this will
help you find common style issues.
1. Any significant changes should almost always be accompanied by tests. The
project already has good test coverage, so look at some of the existing
tests if you're unsure how to go about it. [gocov][] and [gocov-html][]
are invaluable tools for seeing which parts of your code aren't being
exercised by your tests.
1. Do your best to have [well-formed commit messages][] for each change.
This provides consistency throughout the project, and ensures that commit
messages are able to be formatted properly by various git tools.
1. Finally, push the commits to your fork and submit a [pull request][].
[forking]: https://help.github.com/articles/fork-a-repo
[golint]: https://github.com/golang/lint
[golint readme]: https://github.com/golang/lint/blob/master/README
[gocov]: https://github.com/axw/gocov
[gocov-html]: https://github.com/matm/gocov-html
[well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits
[pull request]: https://help.github.com/articles/creating-a-pull-request

View File

@ -1,71 +0,0 @@
gofuzz
======
gofuzz is a library for populating go objects with random values.
[![GoDoc](https://godoc.org/github.com/google/gofuzz?status.png)](https://godoc.org/github.com/google/gofuzz)
[![Travis](https://travis-ci.org/google/gofuzz.svg?branch=master)](https://travis-ci.org/google/gofuzz)
This is useful for testing:
* Do your project's objects really serialize/unserialize correctly in all cases?
* Is there an incorrectly formatted object that will cause your project to panic?
Import with ```import "github.com/google/gofuzz"```
You can use it on single variables:
```go
f := fuzz.New()
var myInt int
f.Fuzz(&myInt) // myInt gets a random value.
```
You can use it on maps:
```go
f := fuzz.New().NilChance(0).NumElements(1, 1)
var myMap map[ComplexKeyType]string
f.Fuzz(&myMap) // myMap will have exactly one element.
```
Customize the chance of getting a nil pointer:
```go
f := fuzz.New().NilChance(.5)
var fancyStruct struct {
A, B, C, D *string
}
f.Fuzz(&fancyStruct) // About half the pointers should be set.
```
You can even customize the randomization completely if needed:
```go
type MyEnum string
const (
A MyEnum = "A"
B MyEnum = "B"
)
type MyInfo struct {
Type MyEnum
AInfo *string
BInfo *string
}
f := fuzz.New().NilChance(0).Funcs(
func(e *MyInfo, c fuzz.Continue) {
switch c.Intn(2) {
case 0:
e.Type = A
c.Fuzz(&e.AInfo)
case 1:
e.Type = B
c.Fuzz(&e.BInfo)
}
},
)
var myObject MyInfo
f.Fuzz(&myObject) // Type will correspond to whether A or B info is set.
```
See more examples in ```example_test.go```.
Happy testing!

View File

@ -1,225 +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 fuzz_test
import (
"encoding/json"
"fmt"
"math/rand"
"github.com/google/gofuzz"
)
func ExampleSimple() {
type MyType struct {
A string
B string
C int
D struct {
E float64
}
}
f := fuzz.New()
object := MyType{}
uniqueObjects := map[MyType]int{}
for i := 0; i < 1000; i++ {
f.Fuzz(&object)
uniqueObjects[object]++
}
fmt.Printf("Got %v unique objects.\n", len(uniqueObjects))
// Output:
// Got 1000 unique objects.
}
func ExampleCustom() {
type MyType struct {
A int
B string
}
counter := 0
f := fuzz.New().Funcs(
func(i *int, c fuzz.Continue) {
*i = counter
counter++
},
)
object := MyType{}
uniqueObjects := map[MyType]int{}
for i := 0; i < 100; i++ {
f.Fuzz(&object)
if object.A != i {
fmt.Printf("Unexpected value: %#v\n", object)
}
uniqueObjects[object]++
}
fmt.Printf("Got %v unique objects.\n", len(uniqueObjects))
// Output:
// Got 100 unique objects.
}
func ExampleComplex() {
type OtherType struct {
A string
B string
}
type MyType struct {
Pointer *OtherType
Map map[string]OtherType
PointerMap *map[string]OtherType
Slice []OtherType
SlicePointer []*OtherType
PointerSlicePointer *[]*OtherType
}
f := fuzz.New().RandSource(rand.NewSource(0)).NilChance(0).NumElements(1, 1).Funcs(
func(o *OtherType, c fuzz.Continue) {
o.A = "Foo"
o.B = "Bar"
},
func(op **OtherType, c fuzz.Continue) {
*op = &OtherType{"A", "B"}
},
func(m map[string]OtherType, c fuzz.Continue) {
m["Works Because"] = OtherType{
"Fuzzer",
"Preallocated",
}
},
)
object := MyType{}
f.Fuzz(&object)
bytes, err := json.MarshalIndent(&object, "", " ")
if err != nil {
fmt.Printf("error: %v\n", err)
}
fmt.Printf("%s\n", string(bytes))
// Output:
// {
// "Pointer": {
// "A": "A",
// "B": "B"
// },
// "Map": {
// "Works Because": {
// "A": "Fuzzer",
// "B": "Preallocated"
// }
// },
// "PointerMap": {
// "Works Because": {
// "A": "Fuzzer",
// "B": "Preallocated"
// }
// },
// "Slice": [
// {
// "A": "Foo",
// "B": "Bar"
// }
// ],
// "SlicePointer": [
// {
// "A": "A",
// "B": "B"
// }
// ],
// "PointerSlicePointer": [
// {
// "A": "A",
// "B": "B"
// }
// ]
// }
}
func ExampleMap() {
f := fuzz.New().NilChance(0).NumElements(1, 1)
var myMap map[struct{ A, B, C int }]string
f.Fuzz(&myMap)
fmt.Printf("myMap has %v element(s).\n", len(myMap))
// Output:
// myMap has 1 element(s).
}
func ExampleSingle() {
f := fuzz.New()
var i int
f.Fuzz(&i)
// Technically, we'd expect this to fail one out of 2 billion attempts...
fmt.Printf("(i == 0) == %v", i == 0)
// Output:
// (i == 0) == false
}
func ExampleEnum() {
type MyEnum string
const (
A MyEnum = "A"
B MyEnum = "B"
)
type MyInfo struct {
Type MyEnum
AInfo *string
BInfo *string
}
f := fuzz.New().NilChance(0).Funcs(
func(e *MyInfo, c fuzz.Continue) {
// Note c's embedded Rand allows for direct use.
// We could also use c.RandBool() here.
switch c.Intn(2) {
case 0:
e.Type = A
c.Fuzz(&e.AInfo)
case 1:
e.Type = B
c.Fuzz(&e.BInfo)
}
},
)
for i := 0; i < 100; i++ {
var myObject MyInfo
f.Fuzz(&myObject)
switch myObject.Type {
case A:
if myObject.AInfo == nil {
fmt.Println("AInfo should have been set!")
}
if myObject.BInfo != nil {
fmt.Println("BInfo should NOT have been set!")
}
case B:
if myObject.BInfo == nil {
fmt.Println("BInfo should have been set!")
}
if myObject.AInfo != nil {
fmt.Println("AInfo should NOT have been set!")
}
default:
fmt.Println("Invalid enum value!")
}
}
// Output:
}

View File

@ -1,472 +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 fuzz
import (
"reflect"
"testing"
"time"
)
func TestFuzz_basic(t *testing.T) {
obj := &struct {
I int
I8 int8
I16 int16
I32 int32
I64 int64
U uint
U8 uint8
U16 uint16
U32 uint32
U64 uint64
Uptr uintptr
S string
B bool
T time.Time
}{}
failed := map[string]int{}
for i := 0; i < 10; i++ {
New().Fuzz(obj)
if n, v := "i", obj.I; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "i8", obj.I8; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "i16", obj.I16; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "i32", obj.I32; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "i64", obj.I64; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "u", obj.U; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "u8", obj.U8; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "u16", obj.U16; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "u32", obj.U32; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "u64", obj.U64; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "uptr", obj.Uptr; v == 0 {
failed[n] = failed[n] + 1
}
if n, v := "s", obj.S; v == "" {
failed[n] = failed[n] + 1
}
if n, v := "b", obj.B; v == false {
failed[n] = failed[n] + 1
}
if n, v := "t", obj.T; v.IsZero() {
failed[n] = failed[n] + 1
}
}
checkFailed(t, failed)
}
func checkFailed(t *testing.T, failed map[string]int) {
for k, v := range failed {
if v > 8 {
t.Errorf("%v seems to not be getting set, was zero value %v times", k, v)
}
}
}
func TestFuzz_structptr(t *testing.T) {
obj := &struct {
A *struct {
S string
}
}{}
f := New().NilChance(.5)
failed := map[string]int{}
for i := 0; i < 10; i++ {
f.Fuzz(obj)
if n, v := "a not nil", obj.A; v == nil {
failed[n] = failed[n] + 1
}
if n, v := "a nil", obj.A; v != nil {
failed[n] = failed[n] + 1
}
if n, v := "as", obj.A; v == nil || v.S == "" {
failed[n] = failed[n] + 1
}
}
checkFailed(t, failed)
}
// tryFuzz tries fuzzing up to 20 times. Fail if check() never passes, report the highest
// stage it ever got to.
func tryFuzz(t *testing.T, f *Fuzzer, obj interface{}, check func() (stage int, passed bool)) {
maxStage := 0
for i := 0; i < 20; i++ {
f.Fuzz(obj)
stage, passed := check()
if stage > maxStage {
maxStage = stage
}
if passed {
return
}
}
t.Errorf("Only ever got to stage %v", maxStage)
}
func TestFuzz_structmap(t *testing.T) {
obj := &struct {
A map[struct {
S string
}]struct {
S2 string
}
B map[string]string
}{}
tryFuzz(t, New(), obj, func() (int, bool) {
if obj.A == nil {
return 1, false
}
if len(obj.A) == 0 {
return 2, false
}
for k, v := range obj.A {
if k.S == "" {
return 3, false
}
if v.S2 == "" {
return 4, false
}
}
if obj.B == nil {
return 5, false
}
if len(obj.B) == 0 {
return 6, false
}
for k, v := range obj.B {
if k == "" {
return 7, false
}
if v == "" {
return 8, false
}
}
return 9, true
})
}
func TestFuzz_structslice(t *testing.T) {
obj := &struct {
A []struct {
S string
}
B []string
}{}
tryFuzz(t, New(), obj, func() (int, bool) {
if obj.A == nil {
return 1, false
}
if len(obj.A) == 0 {
return 2, false
}
for _, v := range obj.A {
if v.S == "" {
return 3, false
}
}
if obj.B == nil {
return 4, false
}
if len(obj.B) == 0 {
return 5, false
}
for _, v := range obj.B {
if v == "" {
return 6, false
}
}
return 7, true
})
}
func TestFuzz_structarray(t *testing.T) {
obj := &struct {
A [3]struct {
S string
}
B [2]int
}{}
tryFuzz(t, New(), obj, func() (int, bool) {
for _, v := range obj.A {
if v.S == "" {
return 1, false
}
}
for _, v := range obj.B {
if v == 0 {
return 2, false
}
}
return 3, true
})
}
func TestFuzz_custom(t *testing.T) {
obj := &struct {
A string
B *string
C map[string]string
D *map[string]string
}{}
testPhrase := "gotcalled"
testMap := map[string]string{"C": "D"}
f := New().Funcs(
func(s *string, c Continue) {
*s = testPhrase
},
func(m map[string]string, c Continue) {
m["C"] = "D"
},
)
tryFuzz(t, f, obj, func() (int, bool) {
if obj.A != testPhrase {
return 1, false
}
if obj.B == nil {
return 2, false
}
if *obj.B != testPhrase {
return 3, false
}
if e, a := testMap, obj.C; !reflect.DeepEqual(e, a) {
return 4, false
}
if obj.D == nil {
return 5, false
}
if e, a := testMap, *obj.D; !reflect.DeepEqual(e, a) {
return 6, false
}
return 7, true
})
}
type SelfFuzzer string
// Implement fuzz.Interface.
func (sf *SelfFuzzer) Fuzz(c Continue) {
*sf = selfFuzzerTestPhrase
}
const selfFuzzerTestPhrase = "was fuzzed"
func TestFuzz_interface(t *testing.T) {
f := New()
var obj1 SelfFuzzer
tryFuzz(t, f, &obj1, func() (int, bool) {
if obj1 != selfFuzzerTestPhrase {
return 1, false
}
return 1, true
})
var obj2 map[int]SelfFuzzer
tryFuzz(t, f, &obj2, func() (int, bool) {
for _, v := range obj2 {
if v != selfFuzzerTestPhrase {
return 1, false
}
}
return 1, true
})
}
func TestFuzz_interfaceAndFunc(t *testing.T) {
const privateTestPhrase = "private phrase"
f := New().Funcs(
// This should take precedence over SelfFuzzer.Fuzz().
func(s *SelfFuzzer, c Continue) {
*s = privateTestPhrase
},
)
var obj1 SelfFuzzer
tryFuzz(t, f, &obj1, func() (int, bool) {
if obj1 != privateTestPhrase {
return 1, false
}
return 1, true
})
var obj2 map[int]SelfFuzzer
tryFuzz(t, f, &obj2, func() (int, bool) {
for _, v := range obj2 {
if v != privateTestPhrase {
return 1, false
}
}
return 1, true
})
}
func TestFuzz_noCustom(t *testing.T) {
type Inner struct {
Str string
}
type Outer struct {
Str string
In Inner
}
testPhrase := "gotcalled"
f := New().Funcs(
func(outer *Outer, c Continue) {
outer.Str = testPhrase
c.Fuzz(&outer.In)
},
func(inner *Inner, c Continue) {
inner.Str = testPhrase
},
)
c := Continue{fc: &fuzzerContext{fuzzer: f}, Rand: f.r}
// Fuzzer.Fuzz()
obj1 := Outer{}
f.Fuzz(&obj1)
if obj1.Str != testPhrase {
t.Errorf("expected Outer custom function to have been called")
}
if obj1.In.Str != testPhrase {
t.Errorf("expected Inner custom function to have been called")
}
// Continue.Fuzz()
obj2 := Outer{}
c.Fuzz(&obj2)
if obj2.Str != testPhrase {
t.Errorf("expected Outer custom function to have been called")
}
if obj2.In.Str != testPhrase {
t.Errorf("expected Inner custom function to have been called")
}
// Fuzzer.FuzzNoCustom()
obj3 := Outer{}
f.FuzzNoCustom(&obj3)
if obj3.Str == testPhrase {
t.Errorf("expected Outer custom function to not have been called")
}
if obj3.In.Str != testPhrase {
t.Errorf("expected Inner custom function to have been called")
}
// Continue.FuzzNoCustom()
obj4 := Outer{}
c.FuzzNoCustom(&obj4)
if obj4.Str == testPhrase {
t.Errorf("expected Outer custom function to not have been called")
}
if obj4.In.Str != testPhrase {
t.Errorf("expected Inner custom function to have been called")
}
}
func TestFuzz_NumElements(t *testing.T) {
f := New().NilChance(0).NumElements(0, 1)
obj := &struct {
A []int
}{}
tryFuzz(t, f, obj, func() (int, bool) {
if obj.A == nil {
return 1, false
}
return 2, len(obj.A) == 0
})
tryFuzz(t, f, obj, func() (int, bool) {
if obj.A == nil {
return 3, false
}
return 4, len(obj.A) == 1
})
}
func TestFuzz_Maxdepth(t *testing.T) {
type S struct {
S *S
}
f := New().NilChance(0)
f.MaxDepth(1)
for i := 0; i < 100; i++ {
obj := S{}
f.Fuzz(&obj)
if obj.S != nil {
t.Errorf("Expected nil")
}
}
f.MaxDepth(3) // field, ptr
for i := 0; i < 100; i++ {
obj := S{}
f.Fuzz(&obj)
if obj.S == nil {
t.Errorf("Expected obj.S not nil")
} else if obj.S.S != nil {
t.Errorf("Expected obj.S.S nil")
}
}
f.MaxDepth(5) // field, ptr, field, ptr
for i := 0; i < 100; i++ {
obj := S{}
f.Fuzz(&obj)
if obj.S == nil {
t.Errorf("Expected obj.S not nil")
} else if obj.S.S == nil {
t.Errorf("Expected obj.S.S not nil")
} else if obj.S.S.S != nil {
t.Errorf("Expected obj.S.S.S nil")
}
}
}